> ## Documentation Index
> Fetch the complete documentation index at: https://docs.styne.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Volumes

> [//]: # (smoke: not executed, it needs a volume of the account to mount and the smoke account holds none)

A volume is a disk that outlives sandboxes. Create it once, mount it into a sandbox when you create the sandbox, and the
files you wrote are there the next time you mount it, in a different sandbox, after the first one is gone.

A volume is an ext4 disk of fixed size kept on one machine of one [region](https://docs.styne.ai/regions.md). Mounting it in a sandbox is a
disk attach, so reads and writes run at local NVMe speed and every POSIX file operation works (fsync, hard links, xattrs,
mmap, flock, direct I/O).

## Create a volume

```bash theme={"theme":"css-variables"}
curl -sS https://api.styne.ai/volumes \
  -H "Authorization: Bearer $STYNE_API_KEY" \
  -H "content-type: application/json" \
  -d '{"name": "data", "sizeMB": 10240}'
```

The answer is `{"volumeID", "name", "token", "sizeMB", "region", "state", "createdAt"}`. `sizeMB` is in MiB and defaults
to 10,240 (10 GiB); the smallest volume is 1,024 and the largest 102,400. `sizeBytes` is accepted too. `region` is
optional and defaults as for a sandbox create. `token` is always empty; it is there because the E2B SDK types ask for it.
A name is 1 to 128 characters of letters, digits, `.`, `_` and `-`, starts with a letter or a digit, and is unique in your
account: a name you already have answers `409 name_taken`.

You pay for the size you ask for, not for what you write. A volume cannot be resized.

## Mount it

```bash theme={"theme":"css-variables"}
curl -sS https://api.styne.ai/sandboxes \
  -H "Authorization: Bearer $STYNE_API_KEY" \
  -H "content-type: application/json" \
  -d '{"templateID": "base", "volumeMounts": [{"name": "data", "path": "/mnt/data"}]}'
```

* `name` is the volume's name or its `volumeID`; `path` is where the guest mounts it. A path is absolute and normalised,
  at most 255 bytes, not `/` and not under `/proc`, `/sys`, `/dev`, `/run`, `/boot` or `/etc`. A sandbox mounts at most 4
  volumes, each once, each at its own path.
* `readOnly: true` mounts the volume read-only. It still takes the volume for this sandbox alone.
* The sandbox is started on the machine that keeps the volume, so it waits for capacity on that machine only and answers
  `503 capacity` when it has none. A volume in another region than the create names answers `422 volume_region_mismatch`;
  leave `region` out to start where the volume is.
* The disk is mounted before the create answers its first call. The answer and `GET /sandboxes/{id}` list the mounts as
  `volumeMounts`.
* One sandbox at a time holds a volume. A create that names a volume a running sandbox holds answers `409 volume_busy`
  at once. A sandbox that is killed gives its volumes back before the kill answers, and a create that names the volume of
  a sandbox still stopping waits for it, so killing a sandbox and mounting its volume in a new one right away works.

A sandbox with a volume is killed, not paused, at its timeout: `autoPause` and `lifecycle.onTimeout: "pause"` answer
`422` together with `volumeMounts`. The volume stays; mount it in a new sandbox. Pausing, snapshotting, forking or
rewinding such a sandbox answers `409 volume_mounted`.

Whatever a program wrote is on the volume once its `fsync` returned, and everything is flushed when the sandbox is killed
or ends at its timeout. If the machine itself fails, the volume is lost: a volume is kept on one machine and is not
backed up.

## List, read and delete

* `GET /volumes` lists your volumes, oldest first: `[{"volumeID", "name", "sizeMB", "region", "state", "attachedTo"?}]`.
  `state` is `ready`, `attached` or `creating`.
* `GET /volumes/{volume}` reads one by name or id.
* `DELETE /volumes/{volume}` removes the data and the name (204). A volume a sandbox holds answers `409 volume_busy`
  (`volume is attached to sandbox <id>`); kill the sandbox first. The ComputeSDK and E2B SDKs retry that answer for you.

## Limits

| What | Limit | When over |
| - | - | - |
| Volumes | see [limits](https://docs.styne.ai/limits.md) | `429 storage_limit`, `limit: volumes` |
| GiB provisioned over all volumes | see [limits](https://docs.styne.ai/limits.md) | `429 storage_limit`, `limit: volume_gib` |
| Volumes per sandbox | 4 | `422` |
| One volume | 1 to 100 GiB | `422` |

Volumes are listed with their price on [billing](https://docs.styne.ai/billing.md).

## E2B and ComputeSDK

The E2B shape works as is: `Volume.create(name)`, `Volume.list()`, `Volume.destroy(id)` and `volumeMounts` on a create.
The ComputeSDK `volume.create/get/list/delete` calls and the `volumes` option of a create map onto the same routes.

## Operations

| Method | Path | What it does |
| - | - | - |
| `POST` | `/volumes` | Create a volume |
| `GET` | `/volumes` | List the account's volumes |
| `GET` | `/volumes/{id}` | Read one volume by name or id |
| `DELETE` | `/volumes/{id}` | Delete a volume |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.