SandboxAPI — Code Execution API for AI Agents

8 languages. gVisor isolation. Stateful sessions with file and package persistence. Streaming, async polling, and MCP-native tools.

Current API version: 3.3.0 · Base URL via RapidAPI: https://sandboxapi.p.rapidapi.com

Quick Start #

Synchronous execution #

curl -X POST https://sandboxapi.p.rapidapi.com/v1/execute \
  -H "Content-Type: application/json" \
  -H "X-RapidAPI-Key: YOUR_API_KEY" \
  -H "X-RapidAPI-Host: sandboxapi.p.rapidapi.com" \
  -d '{"language":"python3","code":"print(\"Hello, World!\")"}'

Response:

{
  "id": "exec_abc123",
  "status": "completed",
  "language": "python3",
  "stdout": "Hello, World!\n",
  "stderr": "",
  "exit_code": 0,
  "execution_time_ms": 42,
  "memory_used_kb": 8192,
  "timeout": 10,
  "created_at": "2026-06-25T10:00:00Z"
}

Stateful session 3.2.0 #

Sessions hold a sandbox open between calls. Files and installed packages persist for the session's idle TTL (max 30 minutes). Each call still runs in a fresh interpreter, so keep durable state on disk.

# 1. Create a session
curl -X POST https://sandboxapi.p.rapidapi.com/v1/sessions \
  -H "X-RapidAPI-Key: YOUR_API_KEY" \
  -d '{"language":"python3","idle_ttl":300}'
# → {"id":"sess_abc","language":"python3","expires_at":"..."}

# 2. Execute — writes durable state to the session filesystem
curl -X POST https://sandboxapi.p.rapidapi.com/v1/sessions/sess_abc/execute \
  -H "X-RapidAPI-Key: YOUR_API_KEY" \
  -d '{"code":"from pathlib import Path\nPath(\"state.txt\").write_text(\"42\")"}'

# 3. Execute again — the file is still there
curl -X POST https://sandboxapi.p.rapidapi.com/v1/sessions/sess_abc/execute \
  -H "X-RapidAPI-Key: YOUR_API_KEY" \
  -d '{"code":"from pathlib import Path\nprint(int(Path(\"state.txt\").read_text()) * 2)"}'
# → stdout: "84\n"

Package installation in a session 3.3.0 #

curl -X POST https://sandboxapi.p.rapidapi.com/v1/sessions/sess_abc/install \
  -H "X-RapidAPI-Key: YOUR_API_KEY" \
  -d '{"manager":"pip","packages":["pandas","numpy"]}'

Supported stable managers for current public runtimes: pip for Python and npm for JavaScript/TypeScript. Top-1k packages per ecosystem are cached for fast installs.

Streaming output 3.1.0 #

curl -N -X POST https://sandboxapi.p.rapidapi.com/v1/execute/stream \
  -H "X-RapidAPI-Key: YOUR_API_KEY" \
  -d '{"language":"python3","code":"for i in range(5):\n  print(i); import time; time.sleep(1)"}'
# → SSE events: stdout, stdout, ..., result

Events use the standard SSE format. The terminal event has event: result with a JSON payload that includes exit_code, execution_time_ms, and memory_used_kb.

Async polling 3.1.0 #

curl -X POST "https://sandboxapi.p.rapidapi.com/v1/execute?async=true" \
  -H "X-RapidAPI-Key: YOUR_API_KEY" \
  -d '{"language":"python3","code":"..."}'
# → {"job_id":"job_xyz","status":"queued","poll_url":"/v1/executions/job_xyz"}

curl https://sandboxapi.p.rapidapi.com/v1/executions/job_xyz \
  -H "X-RapidAPI-Key: YOUR_API_KEY"
# Terminal responses include either result or error fields.

Supported Languages #

LanguageVersionID
Python3.12python3
JavaScriptNode 22javascript
TypeScript5.4typescript
Go1.22go
Java21java
C++GCC 14cpp
CGCC 14c
Bash5.2bash

Request Parameters #

FieldTypeRequiredDefaultDescription
languagestringYesLanguage ID
codestringYesSource code (max 1MB)
timeoutintegerNo10CPU seconds (capped by plan)
stdinstringNo""Standard input

Response Fields #

FieldTypeDescription
idstringExecution ID
statusstringcompleted / error / timeout
languagestringNormalized language ID used for execution
stdoutstringStandard output (max 1MB, may be truncated)
stderrstringStandard error (max 1MB)
exit_codeintegerProcess exit code
execution_time_msintegerCPU time
memory_used_kbintegerPeak memory
timeoutintegerEffective timeout in seconds
created_atstringExecution timestamp
truncatedboolPresent when output was truncated

Error Handling #

SandboxAPI distinguishes between API errors (HTTP 4xx/5xx) and execution errors (HTTP 200 with a status field). Treat any HTTP 200 response as a successful API call — the status tells you whether the user's code ran cleanly.

HTTPMeaningWhat to do
200Execution returned a resultInspect status
400Bad request (missing language, oversize body, etc.)Fix the payload
401 / 403Missing/invalid API keyCheck your RapidAPI subscription
408Execution or queue timeoutRaise timeout within your plan limit or use async polling
413Payload too largeTrim code or stdin
429Rate limit exceededBack off or upgrade tier
500 / 503Internal errorRetry with exponential backoff; report if persistent

Pricing & Rate Limits #

PlanPriceExecutions/moTimeoutBatchSessionsPackagesAsyncStreaming
BasicFree50030s10
Pro$19/mo10,00060s505 concurrenttop-1k cache
Ultra$49/mo50,000300s10020 concurrenttop-1k cache

All plans include gVisor isolation, 8 languages, stdin, batch execution, streaming output, and the playground. Sessions, package install, and async polling are available on paid plans. See pricing for full details.

Security #

Every execution runs inside an OCI container backed by gVisor (runsc) — a user-space kernel that intercepts syscalls before they reach the host. Combined with strict resource limits, no network egress (default), no persistent storage, and per-request cleanup, this gives you a strictly stronger isolation boundary than container-only sandboxes like raw Docker or Kubernetes.

MCP Server #

SandboxAPI is available as an MCP server at https://mcp.sandboxapi.dev/mcp with 5 tools: execute_code, execute_batch, list_languages, get_capabilities, and session_install_packages.

Add to Claude Desktop / Cursor / VS Code:

{
  "mcpServers": {
    "sandboxapi": {
      "url": "https://mcp.sandboxapi.dev/mcp",
      "headers": { "Authorization": "Bearer YOUR_API_KEY" }
    }
  }
}

Full integration guide on the MCP page.

Code Examples #

Python (requests)

import requests

resp = requests.post(
    "https://sandboxapi.p.rapidapi.com/v1/execute",
    headers={
        "X-RapidAPI-Key": "YOUR_API_KEY",
        "X-RapidAPI-Host": "sandboxapi.p.rapidapi.com",
    },
    json={"language": "python3", "code": "print(2 + 2)"},
)
data = resp.json()
print(data["stdout"])  # → "4\n"

JavaScript (fetch)

const resp = await fetch("https://sandboxapi.p.rapidapi.com/v1/execute", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "X-RapidAPI-Key": "YOUR_API_KEY",
    "X-RapidAPI-Host": "sandboxapi.p.rapidapi.com",
  },
  body: JSON.stringify({ language: "javascript", code: "console.log(2 + 2)" }),
});
const data = await resp.json();
console.log(data.stdout); // → "4\n"

Go

req, _ := http.NewRequest("POST", "https://sandboxapi.p.rapidapi.com/v1/execute",
  strings.NewReader(`{"language":"go","code":"package main\nimport \"fmt\"\nfunc main(){fmt.Println(2+2)}"}`))
req.Header.Set("X-RapidAPI-Key", "YOUR_API_KEY")
req.Header.Set("Content-Type", "application/json")
resp, _ := http.DefaultClient.Do(req)
defer resp.Body.Close()
Try it live: open the playground to run any of these snippets in any of the 8 supported languages without writing a client.

Changelog #

VersionHighlights
3.3.0Package installation in sessions with cached package mirrors and supply-chain checks
3.2.0Stateful sessions with persistent files and installed packages
3.1.0SSE streaming output and async execution with polling
2.0.0Ultra tier (50K exec/mo), gVisor isolation, batch up to 100, 300s timeout, playground
1.2.0Pre-warmed sandbox pools, sub-100ms cold starts, memory reporting
1.1.0Batch execution endpoint (/execute/batch)
1.0.0Stable release — Pro tier, rate limit headers, /health endpoint, full error codes
0.3.0All 8 languages, stdin support, /languages endpoint
0.2.0Added TypeScript, Go, Bash
0.1.0Alpha — Python and JavaScript

Read the full release-by-release changelog →