CoreWeave Serverless sandboxes are in public preview.
Before you begin
Complete the sandbox setup for your placement mode. The Python examples require thecwsandbox package and a CoreWeave API access token in the CWSANDBOX_API_KEY environment variable. Replace [API-ACCESS-TOKEN] with your CoreWeave API access token:
[RUNNER-ID] in the examples with that runner’s ID.
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. A CKS policy can’t raise the platform maximum.
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
Usemax_lifetime_seconds in Python. The following examples request the full 30 days and print the sandbox ID so you can reconnect later. Choose the tab for your placement mode:
- Serverless
- CKS
Create a Serverless sandbox
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 complete request formats, see the API reference and Create a sandbox from a Compose file. For Python client defaults, see Sandbox configuration.
Set a default for a CKS runner
A runner-policy default applies to new sandboxes that don’t request their own lifetime. Use this when workloads on a CKS runner should normally receive a longer lifetime. You need theSANDBOX_ADMIN Identity and Access Management (IAM) action to edit the policy.
Policy updates replace the whole policy document. Don’t submit the excerpt as a replacement for an existing policy: that would remove its other constraints.
-
In an interactive terminal, open the runner’s current policy with the authenticated CoreWeave Intelligent CLI:
-
Set
constraints.lifecycle.default_lifetime_secondsto the desired number of seconds. The following YAML is an excerpt showing a 30-day default. Preserve the rest of the existing policy:Runner policy excerpt -
Save and close the editor to submit the update. Retrieve the policy to verify the value:
policy.constraints.lifecycle.defaultLifetimeSeconds. Follow Update a policy for the full read, edit, and replace procedure.
The default applies to sandboxes created after the update. It doesn’t extend running sandboxes. A sandbox can explicitly request a different lifetime up to 30 days. Don’t add max_lifetime_seconds to the policy: the field was retired, and CoreWeave Intelligent CLI rejects a policy document that still contains it. The policy supplies a default, while the platform enforces the maximum.
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. Awith 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
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 and snapshot options, see Sandbox volumes and File system snapshots. The sandbox lifetime is separate from the timeout for a command or API request. Increasingtimeout_seconds or request_timeout_seconds doesn’t extend the sandbox lifetime. For the differences, see Timeouts.