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

# Mount drives

> Mount a drive in a running sandbox, list the mounts, and unmount it.

Mount a [drive](https://docs.baseten.co/drives/overview.md) in a running sandbox to read and write its
files at a path you choose. The sandbox must be in the drive's region. You
can't attach a drive when you create a sandbox; mount it once the sandbox is
running.

> [!NOTE]
>
> Drives are in private preview. [Contact us](mailto:support@baseten.co) to request access for your organization.

[Set up your SDK or the CLI](https://docs.baseten.co/drives/manage.md#set-up) before running these
examples. If you belong to more than one team, [pass that team](https://docs.baseten.co/drives/manage.md#select-a-team)
on the sandbox client and on each drive call.

The examples use a drive named `shared-notes`, created as in
[Create a drive](https://docs.baseten.co/drives/manage.md#create-a-drive), and a running sandbox named
`hello-world` in the same region, created as in
[Create a sandbox](https://docs.baseten.co/sandboxes/manage.md#create-a-sandbox).

## Mount a drive

The mount path must be an absolute path that no other mount uses, such as
`/mnt/notes`. A mount lasts until you [unmount it](#unmount-a-drive).

**To mount `shared-notes` at `/mnt/notes`**:

> [tab] TypeScript
>
> Run the following code:
>
> ```typescript theme={"system"}
> import { SandboxClient } from "@basetenlabs/sandbox";
>
> const client = new SandboxClient({ apiKey: process.env.BASETEN_API_KEY! });
> const sandbox = await client.get({ name: "hello-world" });
> const mount = await sandbox.drives.mount({
>   name: "shared-notes",
>   mountPath: "/mnt/notes",
> });
> console.log(mount.mountPath, mount.readOnly);
> ```

> [tab] Python
>
> Run the following code:
>
> ```python theme={"system"}
> import os
>
> from baseten.sandbox import SandboxClient
>
> with SandboxClient(api_key=os.environ["BASETEN_API_KEY"]) as client:
>     sandbox = client.get(name="hello-world")
>     mount = sandbox.drives.mount(name="shared-notes", mount_path="/mnt/notes")
>     print(mount.mount_path, mount.read_only)
> ```

> [tab] Go
>
> Run the following code:
>
> ```go theme={"system"}
> package main
>
> import (
>     "context"
>     "fmt"
>     "log"
>     "os"
>
>     "github.com/basetenlabs/baseten-go/sandbox"
> )
>
> func main() {
>     ctx := context.Background()
>     client, err := sandbox.NewClient(sandbox.ClientOptions{
>         APIKey: os.Getenv("BASETEN_API_KEY"),
>     })
>     if err != nil {
>         log.Fatal(err)
>     }
>     sb, err := client.Get(ctx, sandbox.GetOptions{Name: "hello-world"})
>     if err != nil {
>         log.Fatal(err)
>     }
>     mount, err := sb.Drives().Mount(ctx, sandbox.DriveMountOptions{
>         Name:      "shared-notes",
>         MountPath: "/mnt/notes",
>     })
>     if err != nil {
>         log.Fatal(err)
>     }
>     fmt.Println(mount.MountPath, mount.ReadOnly)
> }
> ```

> [tab] API
>
> You mount a drive with a call to the
> [sandbox runtime API](https://docs.baseten.co/sandboxes/run-commands.md#call-the-sandbox-runtime-api-over-http). Use
> a token with both the `sandboxes` and `drives` scopes, and set
> `SANDBOX_URL` to the sandbox's URL; see
> [Get the sandbox URL](https://docs.baseten.co/sandboxes/run-commands.md#get-the-sandbox-url).
>
> Run the following command to
> [mount the drive](https://docs.baseten.co/reference/sandbox-api/drive/attach-a-drive-to-a-local-path.md):
>
> ```bash theme={"system"}
> curl --request POST \
>   --url "${SANDBOX_URL%/}/drives/mount" \
>   --header "Authorization: Bearer $SANDBOX_TOKEN" \
>   --header "Content-Type: application/json" \
>   --data '{"driveName": "shared-notes", "mountPath": "/mnt/notes"}'
> ```
>
> The response's `success` field is `true`.

> [tab] CLI
>
> Run the following command:
>
> ```bash theme={"system"}
> baseten sandbox drive mount --name hello-world --drive-name shared-notes --mount-path /mnt/notes
> ```

**To confirm the mount**:

[List the sandbox's drive mounts](#list-drive-mounts). The mount at `/mnt/notes`
is in the list.

With the [CLI set up](https://docs.baseten.co/drives/manage.md#set-up), you can also write a file and
read it back:

```bash theme={"system"}
baseten sandbox exec --name hello-world -- 'echo hello > /mnt/notes/hello.txt && cat /mnt/notes/hello.txt'
```

The command prints `hello`. The file stays on the drive after you unmount it
or delete the sandbox.

## Mount one folder of a drive

Mount a folder of the drive instead of the whole drive. Give the folder's path
from the drive's root, starting with `/`. If the folder doesn't exist,
mounting creates it.

**To mount the drive's `/projects/alpha` folder at `/mnt/alpha`**:

> [tab] TypeScript
>
> Run the following code:
>
> ```typescript theme={"system"}
> import { SandboxClient } from "@basetenlabs/sandbox";
>
> const client = new SandboxClient({ apiKey: process.env.BASETEN_API_KEY! });
> const sandbox = await client.get({ name: "hello-world" });
> await sandbox.drives.mount({
>   name: "shared-notes",
>   mountPath: "/mnt/alpha",
>   drivePath: "/projects/alpha",
> });
> ```

> [tab] Python
>
> Run the following code:
>
> ```python theme={"system"}
> import os
>
> from baseten.sandbox import SandboxClient
>
> with SandboxClient(api_key=os.environ["BASETEN_API_KEY"]) as client:
>     sandbox = client.get(name="hello-world")
>     sandbox.drives.mount(
>         name="shared-notes", mount_path="/mnt/alpha", drive_path="/projects/alpha"
>     )
> ```

> [tab] Go
>
> Run the following code:
>
> ```go theme={"system"}
> package main
>
> import (
>     "context"
>     "log"
>     "os"
>
>     "github.com/basetenlabs/baseten-go/sandbox"
> )
>
> func main() {
>     ctx := context.Background()
>     client, err := sandbox.NewClient(sandbox.ClientOptions{
>         APIKey: os.Getenv("BASETEN_API_KEY"),
>     })
>     if err != nil {
>         log.Fatal(err)
>     }
>     sb, err := client.Get(ctx, sandbox.GetOptions{Name: "hello-world"})
>     if err != nil {
>         log.Fatal(err)
>     }
>     _, err = sb.Drives().Mount(ctx, sandbox.DriveMountOptions{
>         Name:      "shared-notes",
>         MountPath: "/mnt/alpha",
>         DrivePath: "/projects/alpha",
>     })
>     if err != nil {
>         log.Fatal(err)
>     }
> }
> ```

> [tab] API
>
> Run the following command:
>
> ```bash theme={"system"}
> curl --request POST \
>   --url "${SANDBOX_URL%/}/drives/mount" \
>   --header "Authorization: Bearer $SANDBOX_TOKEN" \
>   --header "Content-Type: application/json" \
>   --data '{"driveName": "shared-notes", "mountPath": "/mnt/alpha", "drivePath": "/projects/alpha"}'
> ```

> [tab] CLI
>
> Run the following command:
>
> ```bash theme={"system"}
> baseten sandbox drive mount --name hello-world --drive-name shared-notes --mount-path /mnt/alpha --drive-path /projects/alpha
> ```

## Mount a drive read-only

A read-only mount lets the sandbox read the drive's files but not change them.
Use one for a sandbox that only reads shared inputs.

**To mount `shared-notes` read-only at `/mnt/notes-ro`**:

> [tab] TypeScript
>
> Run the following code:
>
> ```typescript theme={"system"}
> import { SandboxClient } from "@basetenlabs/sandbox";
>
> const client = new SandboxClient({ apiKey: process.env.BASETEN_API_KEY! });
> const sandbox = await client.get({ name: "hello-world" });
> await sandbox.drives.mount({
>   name: "shared-notes",
>   mountPath: "/mnt/notes-ro",
>   readOnly: true,
> });
> ```

> [tab] Python
>
> Run the following code:
>
> ```python theme={"system"}
> import os
>
> from baseten.sandbox import SandboxClient
>
> with SandboxClient(api_key=os.environ["BASETEN_API_KEY"]) as client:
>     sandbox = client.get(name="hello-world")
>     sandbox.drives.mount(
>         name="shared-notes", mount_path="/mnt/notes-ro", read_only=True
>     )
> ```

> [tab] Go
>
> Run the following code:
>
> ```go theme={"system"}
> package main
>
> import (
>     "context"
>     "log"
>     "os"
>
>     "github.com/basetenlabs/baseten-go/sandbox"
> )
>
> func main() {
>     ctx := context.Background()
>     client, err := sandbox.NewClient(sandbox.ClientOptions{
>         APIKey: os.Getenv("BASETEN_API_KEY"),
>     })
>     if err != nil {
>         log.Fatal(err)
>     }
>     sb, err := client.Get(ctx, sandbox.GetOptions{Name: "hello-world"})
>     if err != nil {
>         log.Fatal(err)
>     }
>     _, err = sb.Drives().Mount(ctx, sandbox.DriveMountOptions{
>         Name:      "shared-notes",
>         MountPath: "/mnt/notes-ro",
>         ReadOnly:  true,
>     })
>     if err != nil {
>         log.Fatal(err)
>     }
> }
> ```

> [tab] API
>
> Run the following command:
>
> ```bash theme={"system"}
> curl --request POST \
>   --url "${SANDBOX_URL%/}/drives/mount" \
>   --header "Authorization: Bearer $SANDBOX_TOKEN" \
>   --header "Content-Type: application/json" \
>   --data '{"driveName": "shared-notes", "mountPath": "/mnt/notes-ro", "readOnly": true}'
> ```

> [tab] CLI
>
> Run the following command:
>
> ```bash theme={"system"}
> baseten sandbox drive mount --name hello-world --drive-name shared-notes --mount-path /mnt/notes-ro --read-only
> ```

## Share a drive between sandboxes

Mount the same drive in each sandbox that needs its files. Each sandbox mounts
it separately, at its own mount path, and can mount it read-write or
read-only.

**To pass a file from one sandbox to another**:

This procedure uses a second running sandbox named `reader` in the drive's
region.

1. Run the following command to write a file from `hello-world`, where the
   drive is mounted read-write at `/mnt/notes`:

   ```bash theme={"system"}
   baseten sandbox exec --name hello-world -- 'echo "step 1 done" > /mnt/notes/status.txt'
   ```

2. Run the following command to mount the drive read-only in `reader`:

   ```bash theme={"system"}
   baseten sandbox drive mount --name reader --drive-name shared-notes --mount-path /mnt/notes --read-only
   ```

3. Run the following command to read the file from `reader`:

   ```bash theme={"system"}
   baseten sandbox exec --name reader -- cat /mnt/notes/status.txt
   ```

   The command prints `step 1 done`.

## List drive mounts

Each mount shows the drive's name, the folder of the drive that's mounted (`/`
for the whole drive), the mount path in the sandbox, and whether it's
read-only.

**To list the drives mounted in `hello-world`**:

> [tab] TypeScript
>
> Run the following code:
>
> ```typescript theme={"system"}
> import { SandboxClient } from "@basetenlabs/sandbox";
>
> const client = new SandboxClient({ apiKey: process.env.BASETEN_API_KEY! });
> const sandbox = await client.get({ name: "hello-world" });
> for (const mount of await sandbox.drives.listMounts()) {
>   console.log(mount.driveName, mount.drivePath, mount.mountPath, mount.readOnly);
> }
> ```

> [tab] Python
>
> Run the following code:
>
> ```python theme={"system"}
> import os
>
> from baseten.sandbox import SandboxClient
>
> with SandboxClient(api_key=os.environ["BASETEN_API_KEY"]) as client:
>     sandbox = client.get(name="hello-world")
>     for mount in sandbox.drives.list_mounts():
>         print(mount.drive_name, mount.drive_path, mount.mount_path, mount.read_only)
> ```

> [tab] Go
>
> Run the following code:
>
> ```go theme={"system"}
> package main
>
> import (
>     "context"
>     "fmt"
>     "log"
>     "os"
>
>     "github.com/basetenlabs/baseten-go/sandbox"
> )
>
> func main() {
>     ctx := context.Background()
>     client, err := sandbox.NewClient(sandbox.ClientOptions{
>         APIKey: os.Getenv("BASETEN_API_KEY"),
>     })
>     if err != nil {
>         log.Fatal(err)
>     }
>     sb, err := client.Get(ctx, sandbox.GetOptions{Name: "hello-world"})
>     if err != nil {
>         log.Fatal(err)
>     }
>     mounts, err := sb.Drives().ListMounts(ctx)
>     if err != nil {
>         log.Fatal(err)
>     }
>     for _, mount := range mounts {
>         fmt.Println(mount.DriveName, mount.DrivePath, mount.MountPath, mount.ReadOnly)
>     }
> }
> ```

> [tab] API
>
> Set `SANDBOX_URL` to the sandbox's URL, as in
> [Get the sandbox URL](https://docs.baseten.co/sandboxes/run-commands.md#get-the-sandbox-url),
> then run the following command to
> [list the mounts](https://docs.baseten.co/reference/sandbox-api/drive/list-currently-mounted-drives.md):
>
> ```bash theme={"system"}
> curl --url "${SANDBOX_URL%/}/drives/mount" \
>   --header "Authorization: Bearer $SANDBOX_TOKEN"
> ```
>
> The response's `mounts` field lists each mount.

> [tab] CLI
>
> Run the following command:
>
> ```bash theme={"system"}
> baseten sandbox drive list --name hello-world
> ```
>
> The command prints a table with the columns `DRIVE`, `DRIVE PATH`,
> `MOUNT PATH`, and `READ ONLY`.

## Unmount a drive

Identify the mount by its mount path. To find it, [list the sandbox's drive
mounts](#list-drive-mounts).

**To unmount the drive at `/mnt/notes`**:

> [tab] TypeScript
>
> Run the following code:
>
> ```typescript theme={"system"}
> import { SandboxClient } from "@basetenlabs/sandbox";
>
> const client = new SandboxClient({ apiKey: process.env.BASETEN_API_KEY! });
> const sandbox = await client.get({ name: "hello-world" });
> await sandbox.drives.unmount({ mountPath: "/mnt/notes" });
> ```

> [tab] Python
>
> Run the following code:
>
> ```python theme={"system"}
> import os
>
> from baseten.sandbox import SandboxClient
>
> with SandboxClient(api_key=os.environ["BASETEN_API_KEY"]) as client:
>     sandbox = client.get(name="hello-world")
>     sandbox.drives.unmount(mount_path="/mnt/notes")
> ```

> [tab] Go
>
> Run the following code:
>
> ```go theme={"system"}
> package main
>
> import (
>     "context"
>     "log"
>     "os"
>
>     "github.com/basetenlabs/baseten-go/sandbox"
> )
>
> func main() {
>     ctx := context.Background()
>     client, err := sandbox.NewClient(sandbox.ClientOptions{
>         APIKey: os.Getenv("BASETEN_API_KEY"),
>     })
>     if err != nil {
>         log.Fatal(err)
>     }
>     sb, err := client.Get(ctx, sandbox.GetOptions{Name: "hello-world"})
>     if err != nil {
>         log.Fatal(err)
>     }
>     if err := sb.Drives().Unmount(ctx, sandbox.DriveUnmountOptions{MountPath: "/mnt/notes"}); err != nil {
>         log.Fatal(err)
>     }
> }
> ```

> [tab] API
>
> Set `SANDBOX_URL` to the sandbox's URL, as in
> [Get the sandbox URL](https://docs.baseten.co/sandboxes/run-commands.md#get-the-sandbox-url).
> The mount path goes in the URL, with each `/` encoded as `%2F`.
>
> Run the following command to
> [unmount the drive](https://docs.baseten.co/reference/sandbox-api/drive/detach-a-drive-from-a-local-path.md):
>
> ```bash theme={"system"}
> curl --request DELETE \
>   --url "${SANDBOX_URL%/}/drives/mount/%2Fmnt%2Fnotes" \
>   --header "Authorization: Bearer $SANDBOX_TOKEN"
> ```
>
> The response's `success` field is `true`.

> [tab] CLI
>
> Run the following command:
>
> ```bash theme={"system"}
> baseten sandbox drive unmount --name hello-world --mount-path /mnt/notes
> ```
>
> The command prints `Unmounted the drive at /mnt/notes.`

To confirm, [list the sandbox's drive mounts](#list-drive-mounts). The
mount no longer appears.

## Troubleshoot mounting

| HTTP status | Cause and fix |
| - | - |
| `400` | The request is invalid, such as a drive path that doesn't start with `/`. Fix the path. |
| `403` | The sandbox can't access the drive. Check that drives are turned on for your organization and that the drive is in the sandbox's region. [Contact us](mailto:support@baseten.co) to request access. |
| `409` | Another mount already uses the mount path. Choose another path, or [unmount](#unmount-a-drive) what's there. |

## Next steps

> [card] [Delete a drive](https://docs.baseten.co/drives/manage.md#delete-a-drive)
>
> Permanently remove a drive and its files.

> [card] [Manage drives](https://docs.baseten.co/drives/manage.md)
>
> Create a drive, check it, or replace its labels.
