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 throw away from Python. No cluster management, no Kubernetes YAML.
Sandboxes are integrated with the W&B platform: your W&B credentials work automatically, and sandbox sessions can report metrics to an active W&B run.
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.
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 the W&B Secrets Manager with the W&B Python SDK to access sensitive information such as API keys and tokens in a sandbox.
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.
You can define reusable sandbox configurations using the SandboxDefaults class.
Basic usage
The following code snippet shows how to create a sandbox, run a command inside it, and print the output.
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.
First you create a sandbox with Sandbox.run(). Next, you run the command echo "Hello from W&B Sandboxes!" inside the sandbox using the Sandbox class object’s exec() method. Finally, you print the output to the console.
from wandb.sandbox import Sandbox
with Sandbox.run() as sandbox:
result = sandbox.exec(["echo", "Hello from W&B Sandboxes!"]).result()
print(result.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.
Tutorials and examples
For more in-depth examples, see: