Skip to main content

Code Sandbox

The code sandbox executes untrusted code in isolated workspaces. Public traffic goes through the gateway under /v1/sandbox/*; direct service paths are dev-only shortcuts.

Backends

BackendSelect withNotes
DockerSANDBOX_BACKEND=dockerLocal worker containers managed through Docker. Default for development.
E2BSANDBOX_BACKEND=e2b plus deploy/docker-compose.e2b.ymlRemote/self-hosted E2B control plane for stronger production isolation.

Gateway Paths

The gateway strips /v1/sandbox before forwarding to the sandbox service.

Gateway pathService pathPurpose
POST /v1/sandbox/execute/executeRun Python code.
POST /v1/sandbox/bash/bashRun shell command.
POST /v1/sandbox/read/readRead text file with pagination.
POST /v1/sandbox/read_binary/read_binaryRead binary file/artifact.
POST /v1/sandbox/write/writeWrite a file.
POST /v1/sandbox/grep/grepSearch file contents.
POST /v1/sandbox/glob/globMatch file paths.
GET /v1/sandbox/sessions/sessionsList sessions. Admin only.
DELETE /v1/sandbox/sessions/{tenant_id}/{session_id}/sessions/{tenant_id}/{session_id}Destroy session. Admin only.
POST /v1/sandbox/sessions/{tenant_id}/{session_id}/copysameBulk-write files into a workspace.

Example:

curl http://localhost:8080/v1/sandbox/execute \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"code": "print(42)",
"language": "python",
"tenant_id": "default",
"session_id": "s1"
}'

Artifacts

/execute and /bash can produce artifacts such as plots, tables, reports, and binary files. Agent-runtime recognizes sandbox artifact metadata and streams artifact SSE events so the frontend can attach them to the corresponding tool card.

Docker Isolation

Docker sessions are keyed by tenant and session. A session gets its own container and workspace volume. Defaults include:

SettingDefault
NetworkDisabled
Memory512m
Idle cleanup900 seconds
Max sessions50
UserNon-root worker user

GPU passthrough is opt-in with SANDBOX_GPU_ENABLED=true. GPU network stays disabled unless SANDBOX_GPU_NETWORK_ENABLED=true.

Path Handling

Text read/write paths are validated against absolute paths, null bytes, and .. traversal. grep and glob currently construct shell commands around their path inputs, so treat their path handling as more limited than read/write validation until that code is hardened.

Health and Metrics

PathPurpose
/healthzLiveness.
/readyzReadiness.
/metricsPrometheus metrics when scraped directly inside the network.

Configuration

VariablePurpose
SANDBOX_BACKENDdocker or e2b.
SANDBOX_WORKER_IMAGEDocker worker image.
SANDBOX_IDLE_TIMEOUTIdle cleanup in seconds.
SANDBOX_MEM_LIMITDocker memory limit.
SANDBOX_MAX_SESSIONSConcurrent session ceiling.
SANDBOX_GPU_ENABLEDEnable GPU passthrough.
SANDBOX_GPU_NETWORK_ENABLEDAllow network in GPU containers.
E2B_API_KEY, E2B_DOMAIN, E2B_TEMPLATEE2B backend settings.
E2B_ALLOW_INTERNET_ACCESS, E2B_SECURE_ACCESSE2B network/security controls.