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.
Basic usage
To make values available to processes running inside the sandbox, pass anenvironment_variables dictionary to Sandbox.run:
Session-level defaults
When you need the same variables in several sandboxes, define them once on a session instead of repeating them per sandbox. Individual sandboxes can override session defaults or add their own variables:Remote functions
Remote functions inherit environment variables from the session and can declare their own through the@session.function decorator. The SDK merges function-level variables with session defaults at call time: