Sandbox.run(). It’s for developers who have already created a basic sandbox and want to control the container image, resource allocation, and pre-populated files for their workload.
Choose authentication
These examples run on serverless capacity unless a section specifies CKS. Choose the credential for the account that owns your sandboxes. See Choose and get credentials to obtain a key or token. Run the installation commands in an active Python virtual environment. Save the Python code from your credential tab assandbox_auth.py beside the Python scripts you run from this page. It stores the authentication choice, not your credential. The examples import AUTH from that file and pass it explicitly to each new sandbox or session.
- Forge API key
- CoreWeave API access token
Use your Forge API key through the SDK’s W&B authentication strategy:
sandbox_auth.py
placement_mode="cks" on sandbox creation or in SandboxDefaults. Creating a session with auth=AUTH also authenticates the sandboxes it owns. Keep the same credential when reconnecting, listing, or cleaning up sandboxes.
Pass configuration to Sandbox.run()
Configuration options control how the sandbox is provisioned. Pass them as keyword arguments directly to Sandbox.run():
Resources
Configure CPU and memory to match your workload’s needs and avoid over-provisioning or under-provisioning. UseResourceOptions to set requests and limits:
ResourceOptions uses Kubernetes resource syntax:
Mounted files
Mounted files let you ship configuration, scripts, or other static content into the sandbox before it starts, so your workload has what it needs the moment it runs. Pre-populate files at sandbox startup:mount_path, the absolute path inside the sandbox, and file_content, the file’s contents as bytes. A str is encoded as UTF-8 for you.
Mounted files are read-only. Use write_file() for files that need modification.
Next steps
You now have a sandbox that starts with the container image, resource allocation, and pre-mounted files your workload requires. For reusable configuration across multiple sandboxes, useSandboxDefaults. See the sandbox configuration guide for all ResourceOptions fields, GPU resources, QoS classes, and config-library interop.