Apify AI Code Sandbox

An Actor for secure execution of arbitrary code. Connect using MCP, REST API, or interactive shell. The Actor shuts down automatically after 15 minutes of inactivity.

🖥️ Interactive shell /shell

URL

http://localhost:3000/shell

Launch a specific command

http://localhost:3000/shell?launch=ls

📡 Connect with MCP /mcp

MCP server URL (no authentication required)

http://localhost:3000/mcp

Set up examples

claude mcp add --transport http sandbox http://localhost:3000/mcp
codex mcp add sandbox --url http://localhost:3000/mcp
mcpc connect http://localhost:3000/mcp @sandbox

Code execution API /exec

Run Bash command

curl -X POST http://localhost:3000/exec \
  -H "Content-Type: application/json" \
  -d '{"command": "ls -la", "language": "bash", "cwd": "/sandbox", "timeoutSecs": 5}'

Run Python code

curl -X POST http://localhost:3000/exec \
  -H "Content-Type: application/json" \
  -d '{"command": "print(\"hello\")", "language": "py", "timeoutSecs": 10}'

Run TypeScript code

curl -X POST http://localhost:3000/exec \
  -H "Content-Type: application/json" \
  -d '{"command": "console.log(\"hello\")", "language": "ts", "timeoutSecs": 10}'

Response format

All /exec requests return:

{
    "stdout": "string",
    "stderr": "string",
    "exitCode": 0,
    "language": "shell|js|ts|py"
}

Working directories

Override with cwd parameter (must be within /sandbox).

📁 Filesystem API /fs

Direct file operations using HTTP methods. All paths relative to /sandbox.

Read file or list directory

curl http://localhost:3000/fs/app/log.txt

Write or replace file

curl -X PUT http://localhost:3000/fs/config.json \
  -H "Content-Type: application/json" \
  -d '{"key": "value"}'

Create directory

curl -X POST http://localhost:3000/fs/project/src?mkdir=1

Append to file

curl -X POST http://localhost:3000/fs/log.txt?append=1 \
  -d "New log entry"

Delete file or directory (to delete non-empty directory add recursive=1)

curl -X DELETE http://localhost:3000/fs/temp?recursive=1

Get file metadata

curl -I http://localhost:3000/fs/data.json

🔀 Bridges /bridges

Expose web servers that you start inside the sandbox (your own dev server, a TUI gateway, etc.) at a public URL path on this container, so they're reachable from the browser or other services. Each bridge forwards http://localhost:3000/<path> to http://127.0.0.1:<port>/... over HTTP and WebSocket. Changes apply immediately and persist across restarts.

API examples

# List bridges
curl http://localhost:3000/bridges

# Add a bridge
curl -X POST http://localhost:3000/bridges \
  -H "Content-Type: application/json" \
  -d '{"path": "/openclaw", "target": "http://127.0.0.1:18789/openclaw"}'

# Remove a bridge
curl -X DELETE http://localhost:3000/bridges/openclaw