cwsandbox 1.28.0


pip install cwsandbox

  Latest version

Released: Nov 10, 2026

Project Links

Meta
Author: CoreWeave, Inc.
Requires Python: <4,>=3.11

Classifiers

Development Status
  • 3 - Alpha

Intended Audience
  • Developers

License
  • OSI Approved :: Apache Software License

Programming Language
  • Python :: 3
  • Python :: 3.11
  • Python :: 3.12
  • Python :: 3.13
  • Python :: 3.14

cwsandbox-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 INTERNAL error, before sending the data operation. Authentication and permission errors remain fatal. You can require either path for validation or rollback:

from cwsandbox import DataPlaneMode, Sandbox, SandboxDefaults

# Fail instead of falling back, useful when validating direct connectivity.
with Sandbox.run(data_plane_mode=DataPlaneMode.DIRECT) as sb:
    print(sb.exec(["echo", "direct"]).result().stdout)

# Disable direct access for a group of sandboxes.
defaults = SandboxDefaults(data_plane_mode=DataPlaneMode.GATEWAY)
with Sandbox.run(defaults=defaults) as sb:
    print(sb.exec(["echo", "gateway"]).result().stdout)

Direct credentials are scoped to the requested operation and created lazily. Active streams retain their connection, while a process-wide bounded idle-channel cache prevents large collections of inactive sandbox objects from retaining one socket per sandbox.

The CLI accepts --data-plane-mode=auto|direct|gateway on exec, logs, sh, files read, and files write, with auto as the default. Use gateway to skip direct credential negotiation, or direct to require a direct connection:

cwsandbox exec --data-plane-mode=gateway "$SANDBOX_ID" -- nvidia-smi
cwsandbox logs --data-plane-mode=gateway "$SANDBOX_ID" --tail 100
cwsandbox sh --data-plane-mode=direct "$SANDBOX_ID"
cwsandbox files read --data-plane-mode=gateway "$SANDBOX_ID" /tmp/output.txt

For exec, put CLI options before -- and the remote command after it.

Authentication

Authentication defaults to AuthStrategy.COREWEAVE_API_KEY, which reads CWSANDBOX_API_KEY and sends it as a Bearer token. The strategy argument is optional, so existing callers do not need to change.

To use W&B credentials, install the optional integration and select it explicitly. Credential resolution is delegated to the W&B SDK and supports an active W&B session, WANDB_API_KEY, and the host-specific entry in .netrc:

pip install "cwsandbox[wandb]"
from cwsandbox import AuthStrategy, Sandbox

with Sandbox.run(auth=AuthStrategy.WANDB) as sb:
    ...

Sandboxes are created in your default W&B entity unless you choose one. To pick an entity (for example, a team in a different organization) or a project, pass WandbAuth:

from cwsandbox import Sandbox, WandbAuth

with Sandbox.run(auth=WandbAuth(entity="my-team")) as sb:
    ...

The entity is resolved in this order: WandbAuth(entity=...), the active wandb.run, then W&B settings such as WANDB_ENTITY. AuthStrategy.WANDB is the same as WandbAuth().

W&B authentication is sent in the x-wandb-api-key header; it is not treated as a CoreWeave Bearer token.

Embedding in a long-running host

Scripts and CLIs keep the default: the first owned sandbox registers atexit and, on the main thread, SIGINT/SIGTERM handlers so a signal can stop Sessions and exit.

Long-running hosts that already own process lifecycle should disable those signal handlers before creating a sandbox. atexit still runs on normal process exit. The host is responsible for graceful shutdown and for explicitly stopping sandboxes it owns.

import cwsandbox

cwsandbox.disable_signal_handlers()
CWSANDBOX_DISABLE_SIGNAL_HANDLERS=1

Accepted environment values: 1, true, yes, on (case-insensitive). Configure the API or environment variable before the first owned sandbox; changing the variable afterward has no effect.

Development

See DEVELOPMENT.md for setup and workflow.

For code standards and commit guidelines, see CONTRIBUTING.md.

License

  • The CWSandbox Client library is licensed under the Apache-2.0 license.
  • The CWSandbox Client examples are licensed under the BSD-3-Clause license.
1.28.0 Nov 10, 2026
1.27.0 Nov 06, 2026
1.25.0 Nov 03, 2026
1.24.0 Nov 03, 2026
1.23.0 Nov 01, 2026
1.22.0 Oct 26, 2026
1.21.0 Oct 24, 2026
1.20.0 Oct 24, 2026
1.19.6 Oct 23, 2026
1.19.5 Oct 22, 2026
1.19.4 Oct 20, 2026
1.19.3 Oct 19, 2026
1.19.2 Oct 19, 2026
1.19.1 Oct 13, 2026
1.19.0 Oct 09, 2026
1.18.0 Oct 01, 2026
1.17.0 Sep 28, 2026
1.16.0 Sep 25, 2026
1.15.1 Sep 25, 2026
1.15.0 Sep 25, 2026
1.14.4 Sep 25, 2026
1.14.3 Sep 18, 2026
1.14.2 Sep 04, 2026
1.14.1 Sep 04, 2026
1.14.0 Sep 04, 2026
1.13.0 Sep 04, 2026
1.12.3 Sep 03, 2026
1.12.2 Sep 02, 2026
1.12.1 Sep 02, 2026
1.12.0 Sep 02, 2026
1.11.0 Sep 02, 2026
1.10.0 Sep 01, 2026
1.9.0 Sep 01, 2026
1.8.0 Sep 01, 2026
1.7.0 Aug 24, 2026
1.6.0 Aug 21, 2026
1.5.0 Aug 19, 2026
1.4.0 Aug 18, 2026
1.3.0 Aug 18, 2026
1.2.0 Aug 18, 2026
1.1.1 Aug 17, 2026
1.1.0 Aug 17, 2026
1.0.0 Aug 14, 2026
0.28.0 Aug 14, 2026
0.27.0 Aug 14, 2026
0.26.2 Aug 13, 2026
0.26.1 Jul 31, 2026
0.26.0 Jun 11, 2026
0.25.0 Jun 09, 2026
0.24.0 May 26, 2026
0.23.3 May 21, 2026
0.23.2 May 20, 2026
0.23.1 May 20, 2026
0.23.0 May 08, 2026
0.22.0 Apr 29, 2026
0.21.0 Apr 23, 2026
0.20.0 Apr 22, 2026
0.19.3 Apr 22, 2026
0.19.2 Apr 22, 2026
0.19.1 Apr 21, 2026
0.19.0 Apr 21, 2026
0.18.0 Apr 20, 2026
0.17.0 Apr 17, 2026
0.16.0 Apr 07, 2026
0.15.0 Apr 06, 2026
0.14.0 Apr 03, 2026
0.13.0 Apr 02, 2026
0.12.2 Mar 31, 2026
0.12.1 Mar 26, 2026
0.12.0 Mar 25, 2026
0.11.2 Mar 24, 2026
0.11.1 Mar 24, 2026
0.11.0 Mar 24, 2026
0.10.0 Mar 24, 2026
0.9.0 Mar 12, 2026

Wheel compatibility matrix

Platform Python 3
any

Files in release

Extras:
Dependencies:
cryptography (>=42.0.0)
googleapis-common-protos (>=1.63.0)
grpcio (>=1.78.0)
protobuf (<7,>=5)