# 挂载 Volume
<subtitle>创建沙箱时，将一个或多个 Volume 挂载到指定路径。</subtitle>

创建沙箱时可以挂载一个或多个 Volume。`volume_mounts` 字典的键是沙箱内的挂载路径，值可以是 `Volume` 对象，也可以直接传入 Volume 名称。

```python
from ucloud_sandbox import Volume, Sandbox

volume = Volume.create('my-volume')

# 传入 Volume 对象
sandbox = Sandbox.create(
    volume_mounts={
        '/mnt/my-data': volume,
    },
)

# 或者直接传入 Volume 名称
sandbox = Sandbox.create(
    volume_mounts={
        '/mnt/my-data': 'my-volume',
    },
)

# 沙箱内写入 /mnt/my-data 的文件会持久化保存在 Volume 中
sandbox.files.write('/mnt/my-data/hello.txt', 'Hello, world!')
```

挂载多个 Volume 时，为每个 Volume 指定不同的挂载路径即可：

```python
from ucloud_sandbox import Sandbox

sandbox = Sandbox.create(
    volume_mounts={
        '/mnt/data': 'my-data',
        '/mnt/cache': 'my-cache',
    },
)
```

> 使用 CLI 创建沙箱时，可以通过 `--mount <volume-name>:<path>` 参数挂载 Volume，参阅 [CLI 指南](/docs/agent-sandbox/product/cli.md)。
