Skip to main content

Sandbox States

A sandbox transitions through three states:
StateDescription
PendingSandbox is being created. The container image is being pulled and the container is being started.
RunningSandbox is active and ready to execute code.
TerminatedSandbox has been stopped, either manually via client.delete() or due to a timeout.
from tensorlake.sandbox import SandboxClient

client = SandboxClient()
sandbox = client.create(image="python:3.11-slim")

info = client.get(sandbox.sandbox_id)
print(info.status)  # "Pending", "Running", or "Terminated"

Resource Configuration

Configure CPU, memory, and disk for each sandbox:
sandbox = client.create(
    image="python:3.11-slim",
    cpus=2.0,             # Number of CPUs
    memory_mb=1024,       # Memory in megabytes
    ephemeral_disk_mb=2048  # Ephemeral disk in megabytes
)
ParameterTypeDefaultDescription
cpusfloat1.0Number of CPUs to allocate
memory_mbint512Memory in megabytes
ephemeral_disk_mbint1024Ephemeral disk space in megabytes

Timeouts

Set a timeout to automatically terminate sandboxes that run too long:
sandbox = client.create(
    image="python:3.11-slim",
    timeout_secs=300  # Terminate after 5 minutes
)
If timeout_secs is not set, the sandbox runs until explicitly terminated with client.delete().

Container Images

Specify any Docker image for your sandbox:
# Standard Python image
sandbox = client.create(image="python:3.11-slim")

# Node.js image
sandbox = client.create(image="node:20-slim")

# Custom image with pre-installed dependencies
sandbox = client.create(image="my-registry/my-image:latest")
You can also specify a custom entrypoint:
sandbox = client.create(
    image="python:3.11-slim",
    entrypoint=["python", "-c", "print('Hello from sandbox')"]
)

Secrets

Inject secrets as environment variables:
sandbox = client.create(
    image="python:3.11-slim",
    secret_names=["OPENAI_API_KEY", "DATABASE_URL"]
)
Secrets must be pre-configured in your Tensorlake account using:
tensorlake secrets set OPENAI_API_KEY=<your-key>

Sandbox Information

The SandboxInfo object returned by client.get() contains:
FieldTypeDescription
sandbox_idstrUnique sandbox identifier
namespacestrNamespace the sandbox belongs to
statusSandboxStatusCurrent state (Pending, Running, Terminated)
imagestrContainer image used
resourcesContainerResourcesInfoCPU, memory, and disk allocation
secret_nameslist[str]Injected secret names
timeout_secsintTimeout in seconds
entrypointlist[str]Custom entrypoint command
networkNetworkConfigNetwork configuration
pool_idstrPool ID if created from a pool
created_atstrCreation timestamp
terminated_atstrTermination timestamp

Learn More