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 Sandbox | With Sandbox |
|---|---|
| Agent can only suggest code | Agent can run and verify code |
| No file manipulation | Full filesystem access |
| No web browsing | Browser automation available |
| Stateless | Persistent 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:
| Template | Boot Time | Use Case |
|---|---|---|
code_interpreter | ~60ms | Data analysis, Python scripts |
claude | ~2s | Autonomous coding with Claude Code |
codex | ~2s | Code generation with OpenAI Codex |
desktop | ~5s | GUI automation, browser testing |
base | ~60ms | Custom environments |
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
| Capability | API | Description |
|---|---|---|
| Execute commands | POST /sandboxes/:id/processes | Run any command with args |
| File read/write | GET/POST /sandboxes/:id/files | Upload, download, list files |
| Run to completion | POST /sandboxes/:id/processes | Synchronous; returns stdout/stderr + exit code |
| Pause/Resume | POST /sandboxes/:id/pause | Save state, resume later |
| Networking | Built-in | Outbound internet access |
Limits
| Resource | Limit |
|---|---|
| Boot time | ~60ms (code_interpreter, base) |
| Max lifetime | 1 hour |
| CPU | 2 vCPU |
| Memory | 4 GB |
| Disk | 10 GB |
| Max concurrent | 10 per account |
| File upload | 100 MB |
Next Steps
- Templates — Detailed specs for each template
- Sandbox Lifecycle — States, timeout, keepalive
- Sandbox API — Full API reference

