Skip to main content
The Python Sandbox defaults to 1 CPU, 128 MiB memory, Python 3.11, and a 600-second lifetime. Increase memory for package installation, browsers, or data processing.
Create API_KEY with its approved credential hosts before starting this example:
Runtime secrets receive placeholders, substituted only in HTTPS headers to approved hosts. Existing secrets need host rules before binding. Use env for nonsecret configuration; manually passing a real key through env or a source file remains plaintext. Sandboxes do not inherit your workspace token. Explicit BETA9_TOKEN or BEAM_TOKEN secret bindings are plaintext opt-ins. See networking for credential-host and allowlist interactions. Add gpu, gpu_count, or pool for workloads that need suitable GPU capacity or a compute pool. Requesting a GPU does not install your application’s CUDA libraries; include those in the image.

Persistent Storage

The bucket configuration’s access and secret key fields are Beam secret names, not plaintext credentials. Create those secrets and use a bucket your credentials can access. A durable disk has one writable attachment at a time.

Lifetime

keep_warm_seconds is the sandbox’s TTL, not an idle timeout that every command automatically resets. Use -1 for a sandbox that you will terminate explicitly. Running processes do not make a finite TTL unlimited.
Save the sandbox ID if you need to reconnect. Connecting to an existing sandbox does not create a replacement if it has already terminated.

Other capabilities

Use network controls for outbound restrictions and exposing ports, snapshots for restoring state, and Docker for nested container workloads. Exposed sandbox URLs are public; implement authentication in a service before exposing sensitive functionality. See the Python SDK reference for sandbox methods.