> ## 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.

# 설정

> 샌드박스 리소스, 이미지 및 환경 설정을 구성합니다.

이 예시에서는 `CWSANDBOX_API_KEY`에 설정된 CoreWeave API 액세스 토큰을 사용합니다. Forge API 키 인증은 [시작하기](/ko/products/sandboxes/get-started)를 참조하세요. CKS 요구 사항은 [배치 모드](/ko/products/sandboxes/placement)를 참조하세요.

이 튜토리얼에서는 `Sandbox.run()`에 옵션을 전달하여 시작 시 샌드박스를 설정하는 방법을 보여줍니다. 기본 샌드박스를 이미 생성한 개발자를 대상으로 하며, 워크로드에 대한 컨테이너 이미지, 리소스 할당 및 사전 채워진 파일을 제어하려는 경우에 유용합니다.

<h2 id="pass-configuration-to-sandboxrun">
  `Sandbox.run()`에 설정 전달
</h2>

설정 옵션은 샌드박스가 프로비저닝되는 방식을 제어합니다. 이를 `Sandbox.run()`에 키워드 인수로 직접 전달하세요:

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

with Sandbox.run(
    container_image="python:3.11",
    max_lifetime_seconds=300,
    tags=["my-app"],
) as sandbox:
    sandbox.exec(["python", "--version"]).result()
```

<h2 id="resources">
  리소스
</h2>

워크로드의 요구 사항에 맞게 CPU와 메모리를 설정하여 과도한 프로비저닝이나 부족한 프로비저닝을 피하세요. `ResourceOptions`를 사용하여 requests와 limits를 설정하세요:

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

with Sandbox.run(
    resources=ResourceOptions(
        requests={"cpu": "2", "memory": "2Gi"},
        limits={"cpu": "2", "memory": "2Gi"},
    ),
) as sandbox:
    sandbox.exec(["python", "compute.py"]).result()
```

`ResourceOptions`는 [Kubernetes 리소스 구문](https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/)을 사용합니다:

| 리소스 | 형식 | 예시 |
| - | - | - |
| CPU | 코어 또는 밀리코어 | `"1"`, `"2"`, `"500m"` (0.5 CPU) |
| 메모리 | 단위 접미사가 있는 바이트 | `"512Mi"`, `"1Gi"`, `"2Gi"` |

<h2 id="mounted-files">
  마운트된 파일
</h2>

마운트된 파일을 사용하면 샌드박스가 시작되기 전에 설정, 스크립트 또는 기타 정적 콘텐츠를 샌드박스에 제공할 수 있으므로, 워크로드가 실행되는 순간 필요한 것을 갖출 수 있습니다. 샌드박스 시작 시 파일을 미리 채우세요:

```python theme={"system"}
with Sandbox.run(
    mounted_files=[
        {"mount_path": "/app/config.json", "file_content": b'{"debug": true}'},
        {"mount_path": "/app/script.py", "file_content": b"print('hello')"},
    ]
) as sandbox:
    sandbox.exec(["python", "/app/script.py"]).result()
```

각 항목은 샌드박스 내부의 절대 경로인 `mount_path`와 파일 내용을 바이트로 나타낸 `file_content`를 받습니다. `str`을 전달하면 UTF-8로 자동 인코딩됩니다.

마운트된 파일은 읽기 전용입니다. 수정이 필요한 파일에는 `write_file()`을 사용하세요.

<h2 id="next-steps">
  다음 단계
</h2>

이제 워크로드에 필요한 컨테이너 이미지, 리소스 할당 및 사전 마운트된 파일로 시작하는 샌드박스가 있습니다.

여러 샌드박스에서 재사용 가능한 설정을 위해 `SandboxDefaults`를 사용하세요. 모든 `ResourceOptions` 필드, GPU 리소스, QoS 클래스 및 설정 라이브러리 상호 운용성에 대한 자세한 내용은 [샌드박스 설정 가이드](/ko/products/sandboxes/client/guides/sandbox-configuration)를 참조하세요.
