Skip to content

Cloud Sandboxes

Sandboxes are isolated cloud execution environments that give your agents the ability to run code, manage files, and execute processes. They boot in ~60ms and provide a full Linux environment.

Why Sandboxes?

LLMs can reason about code, but they can't execute it. Sandboxes bridge this gap:

Without SandboxWith Sandbox
Agent can only suggest codeAgent can run and verify code
No file manipulationFull filesystem access
No web browsingBrowser automation available
StatelessPersistent state across interactions

Quick Start

python
import requests

BASE = "https://api.sandbase.ai"
HEADERS = {"Authorization": "Bearer sk-sb-YOUR_KEY"}

# 1. Create a sandbox (boots in ~60ms)
sandbox = requests.post(f"{BASE}/sandboxes", headers=HEADERS, json={
    "templateID": "code_interpreter",
    "timeout": 300
}).json()

sandbox_id = sandbox["sandboxID"]

# 2. Execute code
result = requests.post(f"{BASE}/sandboxes/{sandbox_id}/processes", headers=HEADERS, json={
    "cmd": "python3",
    "args": ["-c", "import pandas as pd; print(pd.__version__)"]
}).json()

print(result["stdout"])  # "2.1.4"

# 3. Upload a file
requests.post(f"{BASE}/sandboxes/{sandbox_id}/files", headers=HEADERS,
    files={"file": ("data.csv", open("data.csv", "rb"))},
    data={"path": "/workspace/data.csv"}
)

# 4. Process the file
result = requests.post(f"{BASE}/sandboxes/{sandbox_id}/processes", headers=HEADERS, json={
    "cmd": "python3",
    "args": ["-c", """
import pandas as pd
df = pd.read_csv('/workspace/data.csv')
print(f"Rows: {len(df)}, Columns: {list(df.columns)}")
print(df.describe().to_string())
"""]
}).json()

print(result["stdout"])

Templates

Choose a template based on your use case:

TemplateBoot TimeUse Case
code_interpreter~60msData analysis, Python scripts
claude~2sAutonomous coding with Claude Code
codex~2sCode generation with OpenAI Codex
desktop~5sGUI automation, browser testing
base~60msCustom environments

Full template details

Sandbox + Agent Integration

Attach a sandbox to an agent session for code execution capabilities:

python
# Create an agent with sandbox access
agent = requests.post(f"{BASE}/default/v1/agents", headers=HEADERS, json={
    "name": "Data Analyst",
    "model": {"name": "claude-sonnet-4"},
    "system": """You are a data analyst. When users ask questions about data,
write Python code to analyze it and execute it in your sandbox.
Always show your work and explain the results.""",
    "tools": [{"type": "mcp", "server": "code-exec"}]
}).json()

# Create a session with a sandbox environment
session = requests.post(f"{BASE}/default/v1/sessions", headers=HEADERS, json={
    "agent_id": agent["id"],
    "environment": {
        "template_id": "code_interpreter",
        "timeout": 600
    }
}).json()

# Now the agent can execute code in its sandbox
response = requests.post(
    f"{BASE}/default/v1/sessions/{session['id']}/events",
    headers=HEADERS,
    json={
        "type": "message",
        "role": "user",
        "content": "Analyze the sales data in /workspace/sales.csv and create a chart"
    }
).json()

Capabilities

CapabilityAPIDescription
Execute commandsPOST /sandboxes/:id/processesRun any command with args
File read/writeGET/POST /sandboxes/:id/filesUpload, download, list files
Run to completionPOST /sandboxes/:id/processesSynchronous; returns stdout/stderr + exit code
Pause/ResumePOST /sandboxes/:id/pauseSave state, resume later
NetworkingBuilt-inOutbound internet access

Limits

ResourceLimit
Boot time~60ms (code_interpreter, base)
Max lifetime1 hour
CPU2 vCPU
Memory4 GB
Disk10 GB
Max concurrent10 per account
File upload100 MB

Next Steps