AI Code Sandbox
Pricing
Pay per usage
AI Code Sandbox
Provides a secure execution environment for code generated by AI agents. Interact with the sandbox through web shell, REST API, or MCP. Supports Python and Node.js runtimes, Claude Code, Codex CLI, and OpenCode coding agents, and persists state.
Pricing
Pay per usage
Rating
5.0
(3)
Developer
Apify
Maintained by ApifyActor stats
2
Bookmarked
39
Total users
7
Monthly active users
15 hours ago
Last modified
Categories
Share
Apify AI Code Sandbox
Secure, isolated container for executing arbitrary code, built for AI coding agents and untrusted code. Connect over MCP, a REST API, or an interactive browser shell. Ships with Claude Code, Codex CLI, and OpenCode pre-configured and ready to launch.
This Actor launches a web server on the Actor container URL that provides interface to the sandbox.
Use cases
- ๐ Run untrusted or AI-generated code safely in an isolated container with controlled resources.
- ๐ค Give AI agents a managed workspace to write, run, and test code โ with state that survives container migrations.
- ๐ Drop in over MCP so any MCP client gains code-execution and filesystem tools, no glue code.
- ๐ป Pair with coding agents (Claude Code, Codex CLI, OpenCode) right in the browser shell.
- ๐ Expose internal services (dev servers, dashboards, TUIs) at a public URL with bridges.
- ๐ญ Orchestrate Apify Actors using the limited-permission
APIFY_TOKENavailable inside the sandbox to run other limited-permission Actors and build data pipelines.
Quickstart
- Run the Actor on the Apify platform (Console or API).
- Open the sandbox landing page (the container URL shown in the Actor output) for live links and connection details.
- Connect with an MCP client, call the REST API, or open the shell.
Examples below use https://UNIQUE-ID.runs.apify.net as the container URL โ replace it with your run's URL.
๐ฅ๏ธ Interactive shell โ /shell
Browser terminal (powered by ttyd) for hands-on work inside the sandbox.
https://UNIQUE-ID.runs.apify.net/shellโ plain Bash shell.โฆ/shell?launch=claudeโ launch Claude Code.โฆ/shell?launch=codexโ launch Codex CLI.โฆ/shell?launch=opencodeโ launch OpenCode.โฆ/shell?launch=<command>โ run any command, then drop into a shell.
The coding agents are installed on first use and start pre-configured against the Apify OpenRouter proxy, billed to your Apify account.
๐ค AI agent instructions
The sandbox landing page is also available as Markdown as the /llms.txt file:
https://UNIQUE-ID.runs.apify.net/llms.txt
๐ก Connect with MCP โ /mcp
Streamable-HTTP MCP endpoint, no authentication required:
https://UNIQUE-ID.runs.apify.net/mcp
Add it to an MCP client:
claude mcp add --transport http sandbox https://UNIQUE-ID.runs.apify.net/mcpcodex mcp add sandbox --url https://UNIQUE-ID.runs.apify.net/mcpmcpc connect https://UNIQUE-ID.runs.apify.net/mcp @sandbox
Tools exposed: execute (shell / JS / TS / Python), read-file, write-file, list-files.
โก Code execution API โ /exec
POST /exec runs a shell command or a code snippet.
- Body:
{ command: string; language?: string; cwd?: string; timeoutSecs?: number } language:bash/sh(or omit) for shell;js/javascript,ts/typescript,py/pythonfor code.- Returns
{ stdout, stderr, exitCode, language }โ200on success,500on a non-zero exit or error.
curl -X POST https://UNIQUE-ID.runs.apify.net/exec \-H "Content-Type: application/json" \-d '{"command": "print(\"hi\")", "language": "py", "timeoutSecs": 10}'
Default working directories: shell โ /sandbox, JS/TS โ /sandbox/js-ts, Python โ /sandbox/py. Override with cwd (must stay within /sandbox).
๐ Filesystem API โ /fs
Direct file operations over HTTP. All paths are relative to /sandbox and validated to stay inside it.
GET /fs/{path}โ read a file (raw bytes) or list a directory (JSON{ path, entries }). Add?download=1to get a file as an attachment or a directory as a ZIP.PUT /fs/{path}โ write/replace a file (creates parent dirs; up to 500 MB).POST /fs/{path}?mkdir=1โ create a directory;?append=1โ append to a file.DELETE /fs/{path}โ delete; add?recursive=1for non-empty directories.HEAD /fs/{path}โ return metadata in the response headers.
curl https://UNIQUE-ID.runs.apify.net/fs/app/log.txt # readcurl -X PUT https://UNIQUE-ID.runs.apify.net/fs/config.json -d '{"key":"value"}' # writecurl -X POST "https://UNIQUE-ID.runs.apify.net/fs/project/src?mkdir=1" # mkdircurl -X DELETE "https://UNIQUE-ID.runs.apify.net/fs/temp?recursive=1" # delete
Prefer a UI? Browse the filesystem at /browse.
๐ Bridges โ /bridges
Expose a web server you start inside the sandbox at a public URL path on the container, reachable over HTTP and WebSocket. Each bridge forwards โฆ/{path} โ http://127.0.0.1:{port}/โฆ.
GET /bridgesโ list current bridges.POST /bridgesโ add one:{ "path": "/myapp", "target": "http://127.0.0.1:3000/myapp" }.PUT /bridgesโ replace all:{ "bridges": [ โฆ ] }.DELETE /bridges/{path}โ remove one.
# Start a server inside the sandbox, then expose it:curl -X POST https://UNIQUE-ID.runs.apify.net/bridges \-H "Content-Type: application/json" \-d '{"path": "/myapp", "target": "http://127.0.0.1:8080"}'# Now reachable at https://UNIQUE-ID.runs.apify.net/myapp/
Bridges can also be set via the bridges input or by writing /sandbox/.bridges.json (changes are picked up live). Longest-path matching and Location-header rewriting are automatic, and bridges persist across restarts.
Health & status โ /health
GET /health reports the service state:
200 { status: "healthy", idleTimeoutSecs, remainingSecs? }503 { status: "initializing" }โ dependencies / setup script still running.503 { status: "unhealthy", message }โ setup failed; check the run log.
remainingSecs counts down to idle shutdown and is present only while an idle timeout is active.
Configuration
All inputs are optional. Set them in the Actor input form or via the API.
| Input | Description |
|---|---|
Agent skills (agentSkills) | SKILLS.md packages for the coding agents โ owner/repo or a repo URL per line, or a JSON array. Defaults to apify/agent-skills. See skills.sh. |
Node.js dependencies (nodeDependencies) | npm packages for JS/TS execution. One package@version per line (npm-style), or a package.json-style JSON object. |
Python requirements (pythonRequirements) | pip packages for Python execution, in requirements.txt format. |
MCP connectors (mcpConnectors) | MCP connectors to pre-load into Claude Code, Codex, and OpenCode, and write to /sandbox/mcp.json for mcpc. |
Setup script (initBashScript) | Bash script run on startup after dependencies install. Output streams to the log (tagged [init]) with a progress heartbeat; 5-minute timeout. |
Environment variables (envVars) | Secret variables exposed only to the setup script, then removed before the shell, MCP server, and code execution start. dotenv or JSON; encrypted at rest. |
Idle timeout (idleTimeoutSecs) | Seconds of inactivity before automatic shutdown (default 900; 0 disables). Activity includes HTTP requests and shell interaction. |
Bridges (bridges) | Bridges to create at startup (see above). |
Dependencies install at startup before any code runs. For cost efficiency, set the Actor's Execution Timeout to 0 (infinite) and let the idle timeout manage the lifecycle. Note that every request to the Actor has a 5-minute ceiling, so each operation must finish within that window.
Sandbox environment
- Base image: Debian Trixie with Node.js 24 and Python 3 (
venvat/sandbox/py/venv). - Pre-installed tools: git, openssh-client, curl, wget, jq, build-essential,
tsx,apify-cli,mcpc, andttyd. Theapify-clientlibrary is preinstalled in the Node environment, and the Pythonapify-clientin the venv. - Pre-configured coding agents: Claude Code, Codex CLI, and OpenCode โ installed on first launch and wired to the Apify OpenRouter proxy (authenticated with
APIFY_TOKEN), with confirmation prompts auto-approved (safe inside the sandbox). - Working directories:
/sandbox(shell),/sandbox/js-ts(npm packages innode_modules),/sandbox/py(Python venv). - Persistence: filesystem changes are backed up to the Actor's key-value store and restored after a container migration, so work survives restarts (dependency directories are excluded and reinstalled).
- Agent context:
AGENTS.mdandCLAUDE.mdare placed in/sandboxto guide the coding agents.


