Skip to main content
The cwsandbox Python client provides a high-level SDK for creating and managing CoreWeave sandbox environments. It supports both synchronous and asynchronous workflows through a unified API.

Prepare your Python environment

Install uv. In your project directory, activate an existing Python 3.11 or later virtual environment, or create one:
Run the installation commands and example scripts from this environment.

Choose authentication

These examples run on serverless capacity unless a section specifies CKS. Choose the credential for the account that owns your sandboxes. See Choose and get credentials to obtain a key or token. Save the Python code from your credential tab as sandbox_auth.py beside the Python scripts you run from this page. It stores the authentication choice, not your credential. The examples import AUTH from that file and pass it explicitly to each new sandbox or session.
Use your Forge API key through the SDK’s W&B authentication strategy:
sandbox_auth.py
For CKS placement, choose the CoreWeave token, enable a runner, and set placement_mode="cks" on sandbox creation or in SandboxDefaults. Creating a session with auth=AUTH also authenticates the sandboxes it owns. Keep the same credential when reconnecting, listing, or cleaning up sandboxes.

Quick start

Create a sandbox, run a command, and retrieve the result:
In async code, use Sandbox(...) with async with to start the sandbox without blocking the event loop. Sandbox.run() calls start().result() internally, which blocks during startup. See Sync versus async patterns.

Migrate from wandb.sandbox

wandb.sandbox is deprecated. Use cwsandbox directly and select authentication explicitly. For account setup, follow the serverless quickstart.

Install and retain Forge authentication

These examples use a Forge SaaS API key on serverless capacity. For a dedicated instance, follow Use sandboxes with W&B Dedicated Cloud. In your active Python environment, install the standalone client and set your key. Replace [WANDB-API-KEY] with your Forge API key:
When you import the deprecated wrapper, it selects Forge authentication:
Before: wandb.sandbox
With cwsandbox, pass the key through AuthHeaders. This route doesn’t require the optional wandb dependency:
After: cwsandbox
Save the migrated example as a file named migrated_sandbox.py, then run it:
Both examples print 4 and stop the sandbox when the with block exits. The migrated example sets max_lifetime_seconds=43200 explicitly to retain the wrapper’s 12-hour default. If your previous configuration selected a team or project, add x-entity-id or x-project-name to headers. Alternatively, follow Choose authentication to use the AuthStrategy.WANDB route. Install cwsandbox[wandb], import AuthStrategy, and pass auth=AuthStrategy.WANDB. This route uses the wandb dependency to resolve a configured session, WANDB_API_KEY, or credentials saved by wandb login. If no credential is configured, it can prompt you. It supports user API keys. The explicit AuthHeaders example reads WANDB_API_KEY through os.environ. That variable alone doesn’t change the client’s default authentication.

Review wrapper defaults

An import change alone doesn’t preserve all wrapper behavior: A CoreWeave API access token supports both serverless and CKS placement. For placement options and account requirements, see Sandbox placement and spillover. If your code uses profile selectors or discovery APIs, follow What changed from profiles and Discover available runners.

Next steps

Use the CLI guide to manage existing sandboxes from your terminal.

Get started

Authenticate and run your first serverless sandbox with the SDK.

Tutorial

Learn to configure sandboxes, run commands, transfer files, and clean up with the Python SDK.

Guides

In-depth guides about specific topics including lifecycle management, file operations, execution patterns, and troubleshooting.
Last modified on November 5, 2026