A Python client library for CoreWeave Sandbox
Actively maintained. Last release 3 weeks ago, commits in 19 of the last 26 weeks. A safe choice.
pip install cwsandboxcwsandbox-client
A Python client library for CWSandboxes.
Documentation
See the documentation site for the full tutorial, guides, and API reference.
Quick Start
from cwsandbox import Sandbox
# Quick one-liner with factory method (sync/async hybrid API)
sb = Sandbox.run("echo", "Hello, World!")
sb.stop().result() # Block for completion
# Context manager for automatic cleanup
with Sandbox.run("sleep", "infinity", container_image="python:3.11") as sb:
result = sb.exec(["python", "-c", "print(2 + 2)"]).result()
print(result.stdout) # 4
# Also works in async contexts
async with Sandbox.run("sleep", "infinity") as sb:
result = await sb.exec(["python", "-c", "print(2 + 2)"])
print(result.stdout) # 4
Command-line interface
Install the optional CLI to inspect and manage existing sandboxes from your terminal:
pip install "cwsandbox[cli]"
export CWSANDBOX_API_KEY="your-api-key"
export SANDBOX_ID="your-sandbox-id"
# Discover and inspect sandboxes
cwsandbox ls
cwsandbox get "$SANDBOX_ID"
# Run a command or open an interactive shell
cwsandbox exec "$SANDBOX_ID" python -c "print('hello')"
cwsandbox sh "$SANDBOX_ID"
# Inspect the main process logs, then stop the sandbox
cwsandbox logs "$SANDBOX_ID" --tail 100 --timestamps
cwsandbox stop "$SANDBOX_ID"
To authenticate with W&B instead, install cwsandbox[cli,wandb] and pass
--auth wandb (or set CWSANDBOX_AUTH=wandb). Credentials come from
WANDB_API_KEY or wandb login; choose the entity and project with
WANDB_ENTITY and WANDB_PROJECT:
WANDB_ENTITY=my-team cwsandbox --auth wandb ls
The CLI operates on sandboxes created with the Python SDK or another client. Run
cwsandbox --help or cwsandbox <command> --help for all commands and options.
Sandbox data connections
Exec, log, and file operations prefer a sandbox-scoped direct mTLS connection. Lifecycle and management operations continue to use the CWSandbox API. The SDK generates the private key in memory, sends only a certificate signing request, and never sends API bearer credentials to the sandbox data endpoint.
The default auto policy uses a short direct-connect budget, then falls back to
the API gateway. It also falls back if direct credential negotiation returns an
error, before sending the data operation. Authentication and permission
errors remain fatal. You can require either path for validation or rollback: