Skip to main content
Run Claude Code inside a CoreWeave sandbox and interact with it from your terminal. This guide covers launching the agent, working on a repository, retrieving a result, and stopping the sandbox. Claude’s model requests still go to your configured model provider.
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.
Export your W&B API key in the terminal where you run this guide. Unset any CoreWeave token so cws-agent selects W&B authentication:
W&B users don’t need the SANDBOX_USER IAM action. That permission applies only when authenticating with a CoreWeave API access token.

Quick start with cws-agent

Follow the cws-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:
Claude Code opens in the sandbox’s project directory. Follow any workspace trust prompts. For API-key authentication, approve the key when prompted. If you need account authentication, exit Claude and run 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:
This command uses Claude’s native approval settings. Accept the workspace trust and API-key prompts before continuing. Ask Claude to create a file you can check afterward:
Exit Claude with /exit. From your local terminal, read the file and save the workspace before stopping compute:
The file should contain 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:
For saved conversations and parallel worktrees, see the 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:
Use Python 3.11 or later and uv:
Save the script for your language using the filename shown. It creates a serverless sandbox, installs Claude Code, and clones the repository passed on the command line. If setup fails, it stops the sandbox before raising the error.
create_claude_sandbox.py
Replace [REPOSITORY-URL] with your repository URL, then run the script:
Record the printed sandbox ID. The sandbox continues running after the script exits, until you stop it or its 4-hour lifetime expires.

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.
On macOS or Linux, save this as attach_sandbox.py:
attach_sandbox.py
Replace [SANDBOX-ID] with the printed ID, then run:
For a sandbox created with a CoreWeave API access token, 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:
Inside the sandbox, start Claude from the cloned repository:
Approve the API key, or complete account sign-in if you aren’t using a key, then accept the workspace trust prompts. Ask Claude to create the 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:
Confirm that the output contains Hello from CoreWeave, then stop the sandbox:
This SDK example has no persistent mount. For larger results, use file operations. For a workspace you can restore into a new sandbox, configure file system snapshots at creation.

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_USER IAM 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:
Last modified on September 17, 2026