CoreWeave Serverless sandboxes are in public preview.
Prerequisites
Before you begin, you need the following:- A Weights & Biases (W&B) API key. These examples use W&B authentication. For other credentials, see Choose a credential.
- A Claude account or API credentials supported by Claude Code.
- A repository URL the sandbox can clone. The examples use a public repository. Private repositories require Git credentials inside the sandbox.
cws-agent selects W&B authentication:
SANDBOX_USER IAM action. That permission applies only when authenticating with a CoreWeave API access token.
Quick start with cws-agent
Follow thecws-agent installation instructions. The tool configures a snapshot volume to save and restore your workspace with file system snapshots.
To use an Anthropic API key, load it into ANTHROPIC_API_KEY in your local terminal before launching or restoring the sandbox. cws-agent passes this variable into the sandbox. API-key authentication doesn’t require browser sign-in. See Claude Code authentication.
Replace [SANDBOX-NAME] with a cws-agent session name for this workspace and [REPOSITORY-URL] with the repository to clone. For the session name, use 1 to 40 lowercase letters, digits, or hyphens, starting with a letter or digit:
cws-agent login [SANDBOX-NAME], then complete /login there. The --permission-mode native option uses Claude’s own approval settings. Without it, cws-agent defaults to bypassing those approval prompts. See permission modes.
If Claude reports Not logged in despite a configured API key and never offers to approve it, exit with /exit, then reconnect with onboarding enabled:
/exit. From your local terminal, read the file and save the workspace before stopping compute:
Hello from CoreWeave. down takes a snapshot and stops the sandbox. Exiting Claude alone leaves it running. If the snapshot fails, inspect cws-agent status [SANDBOX-NAME] and retry after resolving the failure. If you can discard unsaved changes, use cws-agent down [SANDBOX-NAME] --no-snapshot.
To return to the saved workspace, run:
cws-agent sessions guide.
Set up with the Sandbox SDK
Run Python snippets in the virtual environment below. Save TypeScript snippets as.mts files in the project where you install the client, then run them with npx tsx [FILENAME].mts.
Use this path to manage the sandbox directly. It’s independent of cws-agent and doesn’t configure snapshots.
Create the sandbox
Choose a client and install it locally:- Python
- TypeScript
Use Python 3.11 or later and
uv:- Python
- TypeScript
create_claude_sandbox.py
[REPOSITORY-URL] with your repository URL, then run the script:
- Python
- TypeScript
Open Claude Code
Use the SDK to attach your local terminal with W&B authentication. The script forwards keystrokes to a sandbox shell and restores your terminal when the shell exits.- Python
- TypeScript
On macOS or Linux, save this as
attach_sandbox.py:attach_sandbox.py
[SANDBOX-ID] with the printed ID, then run:
- Python
- TypeScript
cwsandbox sh [SANDBOX-ID] is an optional shortcut. Install the cli extra to use it. It requires CWSANDBOX_API_KEY and does not accept W&B keys.
For API-key authentication, enter the key in the sandbox’s Bash shell before starting Claude. The input is hidden and isn’t included in the command history:
sandbox-proof.txt file using the prompt from the quick start. When prompted, approve the file write.
Retrieve the result and stop
Exit Claude with/exit, then exit the sandbox shell with exit. From your local terminal, read the file through the SDK. Replace [SANDBOX-ID] with the printed ID:
- Python
- TypeScript
Hello from CoreWeave, then stop the sandbox:
- Python
- TypeScript
Troubleshoot
Use these checks to resolve common issues:- If sandbox creation fails, check your W&B API key and authentication settings. Only CoreWeave API access tokens require the
SANDBOX_USERIAM action. - If installation, cloning, or model requests fail, check outbound connectivity and the relevant provider credentials. For CoreWeave Kubernetes Service (CKS) placement, your runner’s policy must permit those destinations.
- If the terminal disconnects, attach again while the sandbox is running. To retain a process across terminal disconnects, run it in a terminal multiplexer such as
tmux.
Next steps
For more information, see these guides:- Interactive shells and TTY covers terminal access from the SDK.
- Sandbox lifecycle covers waiting, reconnecting, and stopping.
- Claude Code documentation covers agent configuration and authentication.