Sandbox to create a single sandbox. Use Session to create and manage multiple sandboxes that share the same configuration.
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.Create a single 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) and network configuration:
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(). In that case, the command becomes the sandbox’s main process.
Create multiple sandboxes with a session
UseSession to manage multiple sandboxes. When the session closes, all sandboxes created by that session are stopped automatically.
You can optionally pass a SandboxDefaults object to the 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.
The following code snippet shows how to create a session with default configuration and use it to create two sandboxes: