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

# 샌드박스 장기 실행하기

> 서버리스 샌드박스의 수명을 최대 30일까지 설정하세요.

서버리스 샌드박스는 최대 30일(2,592,000초) 동안 실행할 수 있습니다. 에이전트, 개발 환경 또는 배치 워크로드가 작업을 마칠 수 있는 충분한 시간을 확보하려면 샌드박스를 생성할 때 수명을 설정하세요.

이 가이드에서는 더 긴 수명을 요청하는 방법을 설명합니다.

## Before you begin

[샌드박스 설정](/ko/products/sandboxes/serverless/get-started)을 완료하세요. Python 예시를 실행하려면 `wandb` extra를 포함한 `cwsandbox` 패키지를 설치하고, `WANDB_API_KEY` 환경 변수에 W\&B API 키를 설정해야 합니다. `[WANDB-API-KEY]`를 본인의 W\&B API 키로 바꾸세요.

```bash theme={"system"}
pip install --upgrade 'cwsandbox[wandb]'
export WANDB_API_KEY="[WANDB-API-KEY]"
```

## Choose a lifetime

The lifetime is an upper bound on how long the sandbox can run. The platform terminates it when the lifetime expires, even if work is still in progress. A workload that finishes or a sandbox that you stop can end sooner.

| 설정 | 서버리스 |
| - | - |
| 샌드박스별 수명 | 소프트웨어 개발 키트(SDK) 또는 샌드박스 생성 요청에서 설정하세요. |
| 러너 정책 기본값 | CoreWeave에서 관리합니다. |
| 최대 수명 | 30일. |

An explicit lifetime takes precedence over a runner-policy default. If you omit the lifetime, the platform uses the applicable policy default. If no positive default supplies a lifetime, the platform uses 10 minutes (600 seconds). Set the lifetime explicitly for long-running work instead of relying on a default.

플랫폼은 30일을 초과하는 요청을 거부합니다. 값을 `0`으로 지정해도 실행 시간이 무제한이 되는 것은 아닙니다.

You can't extend the lifetime after a sandbox starts. Choose enough time at creation, and plan to save your work before the deadline.

## Set the lifetime when creating a sandbox

Python에서는 `max_lifetime_seconds`를 사용하세요. 다음 예시는 30일 전체를 요청하고, 나중에 다시 연결할 수 있도록 샌드박스 ID를 출력합니다:

```python title="Create a Serverless sandbox" theme={"system"}
from cwsandbox import AuthStrategy, Sandbox

sandbox = Sandbox.run(
    "sleep", "infinity",
    auth=AuthStrategy.WANDB,
    placement_mode="serverless",
    container_image="python:3.11",
    resources={"cpu": "2", "memory": "4Gi"},
    max_lifetime_seconds=30 * 24 * 60 * 60,
)
sandbox.wait()
print(sandbox.sandbox_id)
```

The script prints the sandbox ID. These examples keep the primary process alive with `sleep infinity` and leave the sandbox running after the script exits. When you finish using the sandbox, stop it.

The same lifetime is available through the other client interfaces:

| 인터페이스 | 수명 설정 |
| - | - |
| Python SDK | `Sandbox.run(max_lifetime_seconds=2592000, ...)`. 클라이언트 전체에 공통 기본값을 설정하려면 `SandboxDefaults(max_lifetime_seconds=2592000)`를 사용하세요. 인수를 명시적으로 지정하면 클라이언트 기본값보다 우선 적용됩니다. |
| TypeScript SDK | `client.run()`에 전달하는 options 객체에 `maxLifetimeSeconds: 2592000`을 지정하세요. |
| Compose 파일 임포트 | `POST /v1/sandboxes:createFromFile` 요청에서 최상위 필드 `maxLifetimeSeconds`를 `2592000`으로 설정하세요. 수명은 Compose 서비스 속성이 아니라 요청 설정입니다. |

요청 형식은 [Compose 파일로 샌드박스 생성하기](/products/sandboxes/serverless/create-from-file)를 참조하세요. Python 클라이언트의 기본값은 [샌드박스 설정](/ko/products/sandboxes/serverless/client/guides/sandbox-configuration#max_lifetime_seconds)을 참조하세요.

## Keep working across client sessions

When a sandbox should outlive the Python script that launches it, create a standalone sandbox, as in the preceding examples. A `with Sandbox.run(...)` context stops the sandbox when the block exits, even if its configured lifetime is 30 days. A `Session` also manages cleanup of the sandboxes it owns. See [Cleanup patterns](client/guides/cleanup-patterns).

To reconnect from another script, replace `[SANDBOX-ID]` with the ID printed at creation:

```python title="Reconnect to a running sandbox" theme={"system"}
from cwsandbox import AuthStrategy, Sandbox

sandbox = Sandbox.from_id(
    "[SANDBOX-ID]",
    auth=AuthStrategy.WANDB,
).result()
result = sandbox.exec(["echo", "Connected"]).result()
print(result.stdout)
```

The command prints `Connected`. Reconnecting doesn't reset the lifetime. When you finish, stop the sandbox explicitly:

```python title="Stop a sandbox" theme={"system"}
from cwsandbox import AuthStrategy, Sandbox

sandbox = Sandbox.from_id(
    "[SANDBOX-ID]",
    auth=AuthStrategy.WANDB,
).result()
sandbox.stop().result()
```

## Plan for expiry

샌드박스 수명이 만료되기 전에 결과나 체크포인트를 샌드박스 외부에 저장하세요. 워크플로가 30일을 넘게 걸리는 경우에는 대체 샌드박스를 생성한 뒤 저장된 상태에서 재개하세요. 지원되는 저장소 및 스냅샷 옵션은 [샌드박스 볼륨](/ko/products/sandboxes/serverless/volumes) 및 [파일 시스템 스냅샷](/products/sandboxes/serverless/file-system-snapshots)을 참조하세요.

The sandbox lifetime is separate from the timeout for a command or API request. Increasing `timeout_seconds` or `request_timeout_seconds` doesn't extend the sandbox lifetime. For the differences, see [Timeouts](client/guides/sandbox-configuration#timeouts).
