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

# Shared Volume

> Mount one persistent volume into two machines — one writer, one read-only reader.

Volumes are durable storage that outlives any machine and can be mounted into
several at once. This example creates a volume, mounts it read-write in one
machine and read-only in another, and shows a write flowing between them.

<Note>
  Requires a deployment with the shared-volume backend enabled (the hosted
  private beta has it).
</Note>

## Setup

```bash theme={"theme":{"light":"one-light","dark":"one-dark-pro"}}
uv pip install "nullspace-sdk==1.0.0"
export NULLSPACE_API_KEY=ns_live_...
export NULLSPACE_API_URL=https://api.your-nullspace-domain
```

## Python

```python shared_volume_example.py theme={"theme":{"light":"one-light","dark":"one-dark-pro"}}
import uuid

from nullspace import Machine, Volume, VolumeMount

volume = Volume.create(f"shared-{uuid.uuid4().hex[:8]}")
writer = reader = None
try:
    writer = Machine.create(
        template="base", timeout=120,
        volumes=[volume.mount("/workspace/shared")],
    )
    reader = Machine.create(
        template="base", timeout=120,
        volumes=[VolumeMount(ref=volume.name, mount_path="/workspace/shared",
                             read_only=True)],
    )

    writer.files.write("/workspace/shared/hello.txt", "hello from shared volume\n")
    print("reader saw:", reader.files.read("/workspace/shared/hello.txt").strip())
finally:
    for machine in (writer, reader):
        if machine is not None:
            machine.kill()
    volume.delete()
```

## Expected output

```text theme={"theme":{"light":"one-light","dark":"one-dark-pro"}}
reader saw: hello from shared volume
```

Writes land in the volume, not the machine rootfs — destroy both machines and
the data stays until `volume.delete()`. The read-only mount makes the reader's
side of the tree immutable; writes there fail with a permission error.

Related: [Volumes overview](../volumes/overview) ·
[Mounting volumes](../volumes/mounting-volumes)
