Skip to main content
W&B Sandboxes is in active development and in private preview. Contact W&B Support at support@wandb.com to request access to this feature.
W&B Sandboxes gives you on-demand, isolated compute environments that you can create, use, and discard using Python. No cluster management, no Kubernetes YAML. W&B Sandboxes is built on top of the CoreWeave Sandbox library. For the underlying API reference and library docs, see the CoreWeave Sandbox documentation.

How it works

A sandbox is a single isolated compute environment. You create it, run commands inside it, and stop it when it is done. Each sandbox runs in its own container with its own filesystem, network, and process space. Sandboxes authenticate using your existing W&B credentials. Use the W&B Secrets Manager with the W&B Python SDK to access sensitive information such as API keys and tokens in a sandbox. A sandbox goes through several states in its lifecycle. When a container is running, you can execute commands inside it. Read, write, and mount read-only files to and from the sandbox. Common examples include reading in a Python script to execute, writing out logs or results, or mounting a directory of data read-only for the sandbox to access. Use a session to manage multiple sandboxes that share configuration. When a session closes, all of its sandboxes are stopped automatically. See Manage multiple sandboxes for more details.

Basic usage

Copy and paste the following code snippet into a Python file and run it. You should see the output Hello from W&B Sandboxes! printed to the console.
Ensure you are logged in to W&B before running the code snippet below. Use the wandb login CLI command and follow the prompts to log in to your W&B account. For more information on how W&B searches for credentials, see the wandb login reference documentation.
  1. Create a sandbox with Sandbox.run().
  2. Run the command echo "Hello from W&B Sandboxes!" inside the sandbox using the Sandbox.exec() method.
  3. Print the output to the console using the Process object returned by Sandbox.exec().
hello_sandbox.py
from wandb.sandbox import Sandbox

with Sandbox.run() as sandbox:
    process = sandbox.exec(["echo", "Hello from W&B Sandboxes!"]).result()
    print(process.stdout)
The sandbox automatically stops when the context manager (the with block) exits. For more information on sandbox lifecycle and states, see Lifecycle of sandboxes.

W&B Sandboxes tutorials

For more in-depth examples, see: