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

# Volumes

> Attach Blaxel Volumes to sandboxes for persistent storage that survives sandbox destruction and recreation, with mount path configuration.

Blaxel Volumes provide persistent storage that survives sandbox destruction and recreation.

<Tip>
  For full documentation on creating, deleting, resizing, and listing volumes, see the [Volumes overview](/Volumes/Overview).
</Tip>

## Attach a volume to a sandbox

<Warning>At this time, you can only attach one volume to a sandbox. A volume can also only be attached to one sandbox at a time.</Warning>

To use a volume, attach it **when you create a sandbox** by passing an array of volume configurations to the `volumes` property.

Each configuration must include the `name` of the volume to attach and the `mountPath` where it will be accessible inside the sandbox's filesystem. The mount path **will override the existing content** of a directory.

Use `createIfNotExists()` / `create_if_not_exists()` so that re-running your setup code is safe even if the sandbox already exists with the volume attached:

<CodeGroup>
  ```typescript TypeScript theme={null}
  import { SandboxInstance } from "@blaxel/core";

  const sandbox = await SandboxInstance.createIfNotExists({
    name: "my-sandbox",
    image: "blaxel/nextjs:latest",
    memory: 4096,
    region: "us-pdx-1",
    volumes: [{
      name: "my-volume",     // Must match the name of the created volume
      mountPath: "/app",     // Directory inside the sandbox
      readOnly: false        // Set to true to prevent writes
    }],
    // ... other sandbox properties
  });
  ```

  ```python Python theme={null}
  from blaxel.core import SandboxInstance

  sandbox = await SandboxInstance.create_if_not_exists({
    "name": "my-sandbox",
    "image": "blaxel/nextjs:latest",
    "memory": 4096,
    "region": "us-pdx-1",
    "volumes": [{
      "name": "my-volume",     # Must match the name of the created volume
      "mount_path": "/app",    # Directory inside the sandbox
      "read_only": False       # Set to True to prevent writes
    }],
    # ... other sandbox properties
  })
  ```
</CodeGroup>

Any files written to the `/app` directory within this sandbox will be stored on `my-volume` and will persist even if this sandbox is deleted.

At this time, you cannot detach a volume from a sandbox.

<CardGroup cols={2}>
  <Card title="Learn more about volumes" icon="box" href="/Volumes/Overview">
    Learn how to create and manage volumes.
  </Card>

  <Card title="Learn more about volume templates" icon="box" href="/Volumes/Volumes-templates">
    Pre-populate volumes with files for faster environment setup.
  </Card>
</CardGroup>
