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

# Volumes

> Persistent named storage you can attach to sandboxes

A volume is named storage that outlives any sandbox. Create it once, attach it to sandboxes at a mount path, write to it, and publish to share the result with future sandboxes. More than one sandbox can write to the same volume.

> [!NOTE]
>
> Sandbox volumes (`prime sandbox volumes`) are separate from [Hosted Training volumes](https://docs.primeintellect.ai/hosted-training/volumes.md), which back Model Factory training runs.

## How a volume works

* A sandbox that attaches a volume gets a **private copy** of the volume's latest published version. The copy is made when the sandbox is created.
* Volumes attach **read-write** (the default) or **read-only** (`:ro`). A read-only attachment cannot write or publish.
* **Publishing** adds one sandbox's changes to the volume as a new version. Sandboxes created after the publish completes see the new version. A running sandbox sees it after a sync. A volume that was never published is empty.
* **Syncing** updates the volume in a running sandbox to the latest published version. See [Sync](#sync).
* Each publish is stored as a [checkpoint](https://docs.primeintellect.ai/sandboxes/checkpoints.md). The publish command shows the checkpoint ID. Use this ID to check the status of the publish.
* A volume is mounted with `noatime`, so reading a file does not update its access time.
* Published data survives sandbox termination; unpublished writes do not. **Publish before deleting a sandbox** whose writes you want to keep.
* A volume is a separate disk: it doesn't count against the sandbox's `disk_size_gb`, and a sandbox checkpoint captures the root filesystem only, never a mounted volume. A volume's capacity is **100 GiB by default**, set at creation, and can grow up to **10 TiB** — see [Size and growth](#size-and-growth).

> [!WARNING]
>
> A mounted volume is not a shared live filesystem. Writes in one sandbox stay in that sandbox until it publishes. A running sandbox does not see publishes from other sandboxes until it syncs. To read the latest version, [sync](#sync) the sandbox or create a new sandbox.

## Checkpoints, fork and restore

A checkpoint holds only the sandbox's root disk. A fork or restore attaches no volume unless you pass `--volume`. The mount path is then an empty directory.

`--volume` attaches the volume at its latest published content. It does not attach the state of the volume at the time of the checkpoint.

```bash CLI theme={null}
prime sandbox fork <sandbox-id> --volume my-data:/data
prime sandbox checkpoint restore <checkpoint-id> --volume my-data:/data:ro
```

A restore that includes memory (`--memory`) does not accept `--volume`. A sandbox with an attached volume cannot be paused, so it cannot be snapshotted or memory-forked.

## Quickstart

```bash CLI theme={null}
# Create an empty volume
prime sandbox volumes create my-data

# Attach it to a new sandbox at /data and write to it
prime sandbox create python:3.11-slim --volume my-data:/data
prime sandbox run <sandbox-id> "bash -c 'echo hello > /data/hello.txt'"

# Publish: the sandbox's changes become a new version of the volume
prime sandbox volumes publish my-data --sandbox <sandbox-id>

# A new sandbox sees the published data; :ro mounts it read-only
prime sandbox create python:3.11-slim --volume my-data:/data:ro
prime sandbox run <sandbox-id-2> "cat /data/hello.txt"
```

```python Python theme={null}
from prime_sandboxes import (
    APIClient,
    CreateSandboxRequest,
    SandboxClient,
    VolumeMount,
)

client = SandboxClient(APIClient())

client.volumes.create("my-data")

writer = client.create(
    CreateSandboxRequest(
        name="writer",
        docker_image="python:3.11-slim",
        volumes=[VolumeMount(name="my-data", mount_path="/data")],
    )
)
client.wait_for_creation(writer.id)
client.execute_command(writer.id, "bash -c 'echo hello > /data/hello.txt'")

# Publishes and waits until the new version is ready
client.volumes.publish(writer.id, "my-data")

reader = client.create(
    CreateSandboxRequest(
        name="reader",
        docker_image="python:3.11-slim",
        volumes=[VolumeMount(name="my-data", mount_path="/data", read_only=True)],
    )
)
client.wait_for_creation(reader.id)
print(client.execute_command(reader.id, "cat /data/hello.txt").stdout)
```

Pass `--volume NAME:/mount/path[:ro]` up to 8 times per sandbox. `:ro` mounts the volume read-only; writable mounts have no suffix.

## Publish

`publish` saves the sandbox's copy and adds its changes to the volume. By default, it waits until the publish is complete. After that, new sandboxes that attach the volume see the changes.

* Each publish includes all changes since the sandbox's last successful publish, or since it attached the volume.
* The publishes of one volume complete one at a time. There is no fixed completion time.
* The CLI and the SDK wait up to 300 seconds. Use `--wait-timeout <seconds>` to change this in the CLI. When the wait ends, the CLI exits with status 1 and the SDK raises `TimeoutError`, but the publish continues.
* `--no-wait` (CLI) or `wait=False` (SDK) returns at once. To check a publish, run `prime sandbox checkpoint get <checkpoint-id>` or call `client.get_checkpoint(...)`. The publish is complete when the state is `DURABLE` and the merge status is `merged`. `DURABLE` alone does not mean that the changes are in the volume.
* If a publish fails, the CLI prints the reason and exits with status 1. The SDK raises `RuntimeError` with the reason. The volume keeps its earlier version, and the sandbox keeps its writes. If the cause stays, a new publish from the same sandbox also fails.
* Read-only attachments cannot publish.

## Multiple writers

Many sandboxes can attach the same volume read-write at the same time. Use CLI `prime` 0.20.4 or later, or SDK `prime-sandboxes` 0.5.11 or later: earlier versions can return before the changes are in the volume. Each sandbox changes only its own copy. Each publish adds its changes to the volume's current version, which can already include publishes from other sandboxes.

In this example, sandboxes A and B attach the same version, and both write the same file. A publishes first, then B. A new sandbox reads B's version.

```bash CLI theme={null}
prime sandbox volumes create shared-data

# A and B attach the same version of the volume
prime sandbox create python:3.11-slim --volume shared-data:/data
prime sandbox create python:3.11-slim --volume shared-data:/data
prime sandbox run <sandbox-a-id> "bash -c 'echo from-a > /data/notes.txt'"
prime sandbox run <sandbox-b-id> "bash -c 'echo from-b > /data/notes.txt'"

# Each command waits until its publish is complete
prime sandbox volumes publish shared-data --sandbox <sandbox-a-id>
prime sandbox volumes publish shared-data --sandbox <sandbox-b-id>

# A new sandbox reads B's version: from-b
prime sandbox create python:3.11-slim --volume shared-data:/data:ro
prime sandbox run <sandbox-c-id> "cat /data/notes.txt"
```

```python Python theme={null}
client.volumes.create("shared-data")


def start(name: str, read_only: bool = False) -> str:
    sandbox = client.create(
        CreateSandboxRequest(
            name=name,
            docker_image="python:3.11-slim",
            volumes=[
                VolumeMount(name="shared-data", mount_path="/data", read_only=read_only)
            ],
        )
    )
    client.wait_for_creation(sandbox.id)
    return sandbox.id


# A and B attach the same version of the volume
writer_a = start("writer-a")
writer_b = start("writer-b")
client.execute_command(writer_a, "bash -c 'echo from-a > /data/notes.txt'")
client.execute_command(writer_b, "bash -c 'echo from-b > /data/notes.txt'")

# Each call waits until its publish is complete
client.volumes.publish(writer_a, "shared-data")
client.volumes.publish(writer_b, "shared-data")

reader = start("reader", read_only=True)
print(client.execute_command(reader, "cat /data/notes.txt").stdout)  # from-b
```

### How changes combine

The last writer wins per file: the last publish replaces the whole file, with its permissions, owner, and extended attributes. "Last" is the order in which the publishes complete, not the order in which the sandboxes write.

* Changes to different files all stay.
* Deletes follow the same rule. If the last publish deletes a directory, or puts a file at its path, the directory is removed with all of its contents, including files that other sandboxes added.
* A moved or renamed item keeps the changes that other sandboxes publish to it.
* If moves from two sandboxes would put a directory inside itself, the later publish fails.

> [!WARNING]
>
> A change to only a file's permissions, owner, modification time, or extended attributes also replaces the file's contents with that sandbox's copy.

## Sync

A volume in a running sandbox shows the content from when the sandbox started, or from its last sync. `sync` updates the volume in the sandbox to the latest published version.

* **Read-write mount:** `sync` first publishes the sandbox's unpublished changes. The platform adds them to the volume as in [How changes combine](#how-changes-combine). Then `sync` updates the volume in the sandbox. After the sync, the sandbox shows its own changes and the changes that other sandboxes published.
* **Read-only mount:** `sync` updates the volume in the sandbox.
* **`--discard` (CLI) or `discard=True` (SDK):** `sync` does not publish the sandbox's unpublished changes. It deletes them. The volume in the sandbox then shows the latest published version.

The sandbox must be running.

```bash CLI theme={null}
# Publish this sandbox's changes, then update the volume in the sandbox.
# The command waits until the sync ends (at most 10 minutes).
prime sandbox volumes sync my-data --sandbox <sandbox-id>

# Delete this sandbox's unpublished changes, then update the volume
prime sandbox volumes sync my-data --sandbox <sandbox-id> --discard

# Return as soon as the platform accepts the sync and let it continue
prime sandbox volumes sync my-data --sandbox <sandbox-id> --no-wait
```

```python Python theme={null}
from prime_sandboxes import VolumeSyncFailedError

try:
    # Waits until the sync ends (at most 10 minutes); wait=False returns at once
    sync = client.volumes.sync(sandbox_id, "my-data")
    print(sync.state)  # DONE
except VolumeSyncFailedError as error:
    print(error.failure)  # for example BUSY
```

> [!WARNING]
>
> During a sync, the volume is not available in the sandbox for a few seconds. File operations on the mount path fail until the sync ends. Stop any work that uses the volume before you sync.

A sync that publishes waits for its publish to be added to the volume. Publishes to a volume are added in the order the platform receives them, so when many sandboxes publish to one volume at the same time, a sync can take a few minutes.

### Sync failures

When a sync fails, the platform restores the volume in the sandbox to its state before the sync. The unpublished changes stay in the sandbox. The exceptions are `DEADLINE` and `ROLLBACK_FAILED`: the volume can be missing from the sandbox. In that case, run the sync again.

| Reason | Meaning | Action |
| - | - | - |
| `BUSY` | A process in the sandbox keeps a file on the volume open. | Close the file. Run the sync again. |
| `PUBLISH_FAILED` | The platform could not publish the sandbox's changes. | Run the sync again. |
| `MERGE_FAILED` | The platform could not add the sandbox's changes to the volume. | Check [How changes combine](#how-changes-combine) and [Size and growth](#size-and-growth). |
| `DEADLINE` | The sync took more than 10 minutes. | Run the sync again. |
| `NODE_ERROR` | A platform error stopped the sync. | Run the sync again. |
| `ROLLBACK_FAILED` | The sync failed, and the platform could not restore the volume. | Run the sync again. |

## Import a local directory

```bash theme={null}
prime sandbox volumes create my-data --from ./dataset
```

Combine `--from` with `--size-gb` to size the new volume in the same step.

`--from` needs `rsync` on your machine. The CLI copies the directory through a short-lived helper sandbox and publishes from it; the helper is deleted once the publish is complete. If the volume already exists, the import publishes like any other sandbox: its files are added to the volume's current version.

## Size and growth

A volume's capacity is the maximum it can hold, set at creation in whole GiB: 100 (the default) up to 10240 (10 TiB). `volumes list` and `volumes get` show it as **Capacity**; the SDK exposes it as `Volume.size_gb`.

```bash CLI theme={null}
prime sandbox volumes create my-data --size-gb 512
```

```python Python theme={null}
volume = client.volumes.create("my-data", size_gb=512)
print(volume.size_gb)
```

Grow an existing volume to a larger size:

```bash CLI theme={null}
prime sandbox volumes grow my-data --size-gb 2048
```

```python Python theme={null}
client.volumes.grow("my-data", 2048)
```

* Growth is one-way: a size at or below the volume's current size returns 409. Volumes cannot shrink.
* A grow applies to sandboxes created after it; running sandboxes keep their current size. The filesystem is grown when a sandbox attaches the volume read-write, and publishing from that sandbox records the larger size. Until then, a read-only attachment shows the last published size.
* Large grows add a few seconds to sandbox startup. Pick the size you need at creation.
* Capacity is a ceiling, not a quota: billing stays based on stored data, as documented at the bottom of this page.

> [!WARNING]
>
> Do not grow a volume while more than one sandbox writes to it. Sandboxes that started from different sizes of the volume cannot combine their changes. The later publish fails, the volume keeps its earlier version, and publishing again does not fix it.

## Manage volumes

```bash CLI theme={null}
prime sandbox volumes list --num 50
prime sandbox volumes get my-data
prime sandbox volumes delete my-data
```

```python Python theme={null}
page = client.volumes.list(page=1, per_page=50)
print(page.volumes, page.has_next)

volume = client.volumes.get("my-data")
print(volume.head_checkpoint_id)  # None until the first publish is complete

client.volumes.delete("my-data")
```

* `list` paginates with `--page` / `--num` (max 100 per page); `--json` prints raw fields.
* `delete` fails with 409 while any active sandbox has the volume attached, and removes the volume and all of its published data. Deleting a team volume requires a team admin.

### Scopes and permissions

* Volumes are personal by default. Pass `--team-id` (CLI) or `team_id` (SDK) to work in a team; without it, the CLI uses the team from your config, if any.
* Team members can create, attach, publish, and sync team volumes; only team admins can delete them.
* API tokens need the `sandbox:read` scope to list or get volumes and `sandbox:write` to create, delete, publish, or sync.

### Names and mount paths

* Volume names: 1–40 characters, lowercase letters, digits, and hyphens; must start and end with a letter or digit; unique within their scope.
* Mount paths: absolute, not `/`, unique per sandbox, and not nested inside each other.

## Common errors

| Error | Cause | Fix |
| - | - | - |
| 404 `Volume not found` | No volume with that name in your scope | Check `prime sandbox volumes list` and your team scope |
| 409 `A volume with this name already exists in this scope` | Name taken on create | Pick another name or use the existing volume |
| 409 `Volume is mounted by sandboxes: <IDs>` | Delete while attached. The message lists up to 5 sandbox IDs. | Delete or stop the attached sandboxes first |
| 400 `Read-only attachments cannot publish` | Publishing a `:ro` mount | Attach writable, then publish |
| 404 `Volume is not attached to this sandbox` | Publishing or syncing a name this sandbox doesn't have | Check the sandbox's `--volume` mounts |
| 409 `Sync requires an owned running sandbox` or `Sandbox is no longer running` | Syncing a sandbox that is not running | Start the sandbox, then sync |
| 409 `A sync with a different discard flag is in flight` | A sync with the other `--discard` setting is in progress | Wait for it to end, or repeat the request with the same setting |
| Sync failed with a reason | See [Sync failures](#sync-failures) | Use the action in that table |
| 409 on `grow` | New size at or below the volume's current size | Grow to a larger size in whole GiB; volumes cannot shrink |
| `volume merge failed` on publish | The platform could not add this publish's changes to the volume | Read the reason in the message, then see [Publish](#publish) and [Size and growth](#size-and-growth) |

Published volume data is billed as [checkpoint storage](https://docs.primeintellect.ai/sandboxes/overview.md#pricing).
