Skip to main content
Serverless sandboxes can run for up to 30 days (2,592,000 seconds). Set the lifetime when you create the sandbox to give an agent, development environment, or batch workload enough time to finish. This guide shows how to request a longer lifetime.

Before you begin

Complete the sandbox setup. The Python examples require the cwsandbox package with the wandb extra and a W&B API key in the WANDB_API_KEY environment variable. Replace [WANDB-API-KEY] with your W&B 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. 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. The platform rejects requests above 30 days. A value of 0 doesn’t mean unlimited runtime. 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

Use max_lifetime_seconds in Python. The following example requests the full 30 days and prints the sandbox ID so you can reconnect later:
Create a Serverless sandbox
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: For Python client defaults, see Sandbox configuration.

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. To reconnect from another script, replace [SANDBOX-ID] with the ID printed at creation:
Reconnect to a running sandbox
The command prints Connected. Reconnecting doesn’t reset the lifetime. When you finish, stop the sandbox explicitly:
Stop a sandbox

Plan for expiry

Save results or checkpoints outside the sandbox before its lifetime expires. If a workflow needs more than 30 days, create a replacement sandbox and resume from saved state. For supported storage options, see Sandbox volumes. 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.
Last modified on September 30, 2026