Create W&B Serverless Sandboxes to run code in isolated environments. Start a single sandbox, run commands in it, and manage multiple sandboxes with a session. Each sandbox runs in its own container, with its own file system, network, and process space.Documentation Index
Fetch the complete documentation index at: https://wb-21fd5541-style-guide-sandboxes-20260526-215517.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
By default, sandboxes use
python:3.11 as the base image. To use a different image, pass container_image to Sandbox.run() or SandboxDefaults. W&B supports public container images only.The following code snippet creates a sandbox with the python:3.15 image and runs python --version inside it.Create a sandbox
UseSandbox.run() to create and start a sandbox. This method returns a Sandbox object that you can use to interact with the environment.
The following example creates a sandbox with the default container image (python:3.11):
Start a sandbox without a main command
CallSandbox.run() without a command when you want to create a sandbox first and run work inside it later.
Start a sandbox with a main command
You can also pass a command toSandbox.run(). Use this pattern when the sandbox runs a single job from start to finish. When the main process exits, the sandbox enters a terminal state such as COMPLETED or FAILED.
The command you provide to Sandbox.run() starts as the sandbox’s main process.
Sandbox.run() returns a Sandbox object that you can use to monitor the command and wait for it to finish. For example, to wait for the command to complete and retrieve its result:
Create multiple sandboxes with a session
When you need more than one sandbox at a time, or want to share configuration across several sandboxes, use a session. UseSession to create and manage multiple sandboxes. When the session closes (for example, when you exit a with block), it automatically stops all sandboxes it created.
You can optionally pass a SandboxDefaults object to a session to define reusable default configuration for all sandboxes created by that session. For example, you can specify a default container image, network configuration, or maximum lifetime for all sandboxes in the session.
session.sandbox() returns an unstarted sandbox. It auto-starts when you call Sandbox.exec(), Sandbox.read_file(), or any other operation.
The following code snippet creates a session with two sandboxes that share a default configuration (SandboxDefaults):