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

# 볼륨

> 샌드박스가 유지되는 동안 사용할 수 있는 쓰기 가능한 스크래치 공간을 샌드박스에 제공합니다.

<Note>
  The examples on this page omit `auth`. To authenticate with your W\&B API key, install `cwsandbox[wandb]` and pass `auth=AuthStrategy.WANDB` to `Sandbox.run()`, `Sandbox()`, or `Sandbox.session()`. See [Get started](/products/sandboxes/serverless/get-started).
</Note>

볼륨은 샌드박스가 사용자가 지정한 경로에 마운트하는 저장소입니다. **스크래치 볼륨**은 하나의 샌드박스에 속하며 해당 샌드박스와 함께 삭제됩니다.

이 페이지는 컨테이너 파일 시스템 용량을 초과하는 데이터를 샌드박스에서 써야 하는 개발자를 위한 문서입니다. 이 문서를 마치면 스크래치 볼륨을 연결할 수 있습니다.

## Scratch volumes

A scratch volume is created with the sandbox and destroyed with it. Declare one with `ScratchVolumeOptions` in the `volumes` list.

```python theme={"system"}
from cwsandbox import Sandbox, ScratchVolumeOptions

with Sandbox.run(
    container_image="ubuntu:22.04",
    volumes=[ScratchVolumeOptions(name="workspace", mount_path="/workspace", size="10Gi")],
) as sandbox:
    sandbox.exec(["sh", "-c", "echo hello > /workspace/data.txt"]).result()
```

`ScratchVolumeOptions` accepts the following fields:

| 필드 | 설명 |
| - | - |
| `name` | 샌드박스 내 볼륨 이름입니다. 마운트와 스냅샷에서 이 이름을 참조합니다. 필수 항목입니다. |
| `mount_path` | 기본 컨테이너에 마운트할 절대 경로입니다. 생략하면 볼륨을 마운트하지 않고 선언만 합니다. |
| `size` | 볼륨 크기입니다(예: `"10Gi"`). 생략하면 플랫폼 기본값이 사용됩니다. |
| `medium` | 기반 저장소입니다. `StorageMedium.DISK`(기본값) 또는 `StorageMedium.MEMORY` 중 하나입니다. |
| `sub_path` | 볼륨 루트 대신 마운트할 볼륨 내부의 상대 경로입니다. |
| `read_only` | 볼륨을 읽기 전용으로 마운트합니다. 기본값은 `False`입니다. |
| `restore_from_snapshot_id` | 생성 시 [파일 시스템 스냅샷](/products/sandboxes/serverless/file-system-snapshots)을 볼륨에 복원합니다. |

### Choose a storage medium

`StorageMedium.DISK` backs the volume with local disk. `StorageMedium.MEMORY` backs it with tmpfs, which is faster but counts against the mounting container's memory request and against the policy's memory ceiling.

Because an unbounded RAM-backed volume could exhaust the node, a `MEMORY` volume must declare a `size`. It may do so as an absolute quantity, or as an integer percentage of the sandbox's resolved memory request, such as `"50%"`. The percentage form is valid only for `MEMORY`. A `DISK` volume must use an absolute size.

```python theme={"system"}
from cwsandbox import Sandbox, ScratchVolumeOptions, StorageMedium

with Sandbox.run(
    container_image="ubuntu:22.04",
    volumes=[
        ScratchVolumeOptions(
            name="fast-cache",
            mount_path="/cache",
            size="50%",
            medium=StorageMedium.MEMORY,
        )
    ],
) as sandbox:
    sandbox.exec(["sh", "-c", "df -h /cache"]).result()
```

### Mount a scratch volume on several containers

`mount_path` is a convenience that mounts the volume on the primary container. In a multi-container sandbox, omit `mount_path` and declare the mounts on each container instead, so that more than one container can reach the same volume.

```python theme={"system"}
from cwsandbox import Container, Sandbox, ScratchVolumeOptions, VolumeMount

with Sandbox.run(
    volumes=[ScratchVolumeOptions(name="shared", size="5Gi")],
    containers=[
        Container(
            name="app",
            image="ubuntu:22.04",
            primary=True,
            volume_mounts=[VolumeMount(volume="shared", mount_path="/data")],
        ),
        Container(
            name="sidecar",
            image="ubuntu:22.04",
            volume_mounts=[VolumeMount(volume="shared", mount_path="/data", read_only=True)],
        ),
    ],
) as sandbox:
    sandbox.exec(["sh", "-c", "echo shared > /data/note.txt"]).result()
```

## Related resources

For more on related sandbox features, see the following resources:

* [파일 시스템 스냅샷](/products/sandboxes/serverless/file-system-snapshots): 샌드박스의 파일 시스템을 저장하고 복원합니다.
* [샌드박스 설정](/ko/products/sandboxes/serverless/client/guides/sandbox-configuration): 그 밖의 샌드박스 생성 옵션
