sandbox-mcp
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@sandbox-mcp run uname -a"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
sandbox-mcp 
Local AI agent sandbox. Run isolated Linux VMs on your Mac in ~60ms. No cloud costs. VM-level isolation via Virtualization.framework. Works with MCP clients that support local stdio servers (Claude Code, Claude Desktop, Cursor).
What this is
An MCP server that gives AI agents a sandboxed Linux environment using Apple Containerization (Virtualization.framework). Each sandbox is a real VM — not a container sharing your kernel — that boots in ~700ms and executes commands in ~60ms via a persistent shell over vsock.
Compared to cloud sandboxes (as of early 2025):
Exec latency | Cost | Isolation | |
This (local) | ~60ms | Local hardware | VM (Virtualization.framework) |
E2B | ~150ms + network | $0.18/hr | Firecracker microVM |
Daytona | ~90ms + network | Usage-based | Docker container |
Related MCP server: sandbox-as-a-service-mcp
Quick demo
Once registered, your MCP client can use the sandbox tools directly:
Agent: exec(command="uname -a")
→ Linux mcp-sb-abc123 6.12.6 #1 SMP aarch64 Linux
Agent: install(packages="python3 py3-pip")
→ Installed python3 py3-pip (1230ms)
Agent: exec(command="python3 -c 'print(sum(range(1000)))'")
→ 499500
Agent: bg(command="python3 -m http.server 8000")
→ Started [bg-a1b2c3] PID 42
Agent: expose(port=8000)
→ Forwarding localhost:8000 → 'default':8000
Open http://localhost:8000Cold boot is ~700ms, subsequent commands ~60ms each.
Requirements
Apple Silicon Mac (M1+)
macOS 15 Sequoia+
Python 3.11+
uv (for packaging)
Setup
1. Install Apple Containers
# Download and install the container CLI
curl -LO https://github.com/apple/containerization/releases/download/v0.9.0/container-v0.9.0.pkg
sudo installer -pkg container-v0.9.0.pkg -target /
# Start the container system (downloads kernel on first run)
container system start
# Verify it works
time container run --rm alpine echo "hello" # ~700ms cold boot2. Build the dev image
The included Containerfile.mcp-dev builds an Alpine image pre-loaded with Python, Node.js, Go, Rust, and standard build tools:
cd sandbox-mcp
container build -t mcp-dev -f Containerfile.mcp-dev .3. Install the MCP server
uv sync4. Register with your MCP client
Claude Code:
claude mcp add sandbox -- uv --directory /path/to/sandbox-mcp run sandbox-mcpManual (~/.claude.json):
{
"mcpServers": {
"sandbox": {
"type": "stdio",
"command": "/path/to/uv",
"args": ["--directory", "/path/to/sandbox-mcp", "run", "sandbox-mcp"]
}
}
}5. Building the optimized kernel (optional)
Apple's containerization repo includes a stripped-down Linux kernel config. Compiling it yourself doesn't meaningfully improve exec latency — the ~700ms floor is VM lifecycle overhead (Virtualization.framework + EXT4 + network + vminitd), not kernel boot. The real win is keeping VMs warm and using persistent shell exec (~60ms).
That said, if you want a smaller kernel:
git clone https://github.com/apple/containerization.git
cd containerization/kernel
make # ~3 min on M-series
container system kernel set --binary ./vmlinux
container system stop && container system startHow it works
Agent ──MCP/stdio──▶ sandbox_mcp_server.py (FastMCP)
│
├── SandboxManager
│ ├── _sandboxes: dict[name, Sandbox]
│ ├── _port_forwards: dict[port, PortForward]
│ ├── _sync_jobs: dict[id, SyncJob]
│ └── _cleanup_loop (idle TTL + child TTL)
│
├── SandboxCtlServer (per-parent UDS listener)
│ └── NDJSON over /run/sandbox-ctl.sock
│ → spawn, list, exec, destroy, run
│
└── Sandbox (per-VM)
├── PersistentShell (container exec -i <name> sh)
├── _bg_processes: dict[id, Process]
└── _audit_log: dequeLatency breakdown:
Cold boot: ~700ms (Virtualization.framework + EXT4 + network + vminitd)
Warm exec: ~60ms (command piped to persistent shell via vsock)
Why warm is fast: Each sandbox holds open a
container exec -i <name> shprocess. Commands are written to stdin with a unique end-marker, output is read until the marker appears. No process spawn overhead per command.
Port forwarding
Apple Containers v0.9.0 -p port publishing is broken (TCP connects but data never flows), and VM IPs are not routable from the host. Port forwarding works via asyncio TCP proxy:
exposestarts a local TCP server on127.0.0.1:<host_port>Each incoming connection spawns
container exec -i <name> nc 127.0.0.1 <container_port>Data is piped bidirectionally between the client and the nc process via vsock
Multi-sandbox
Sandboxes are named (default: "default"). Each gets isolated volumes for /workspace and package caches (apk, pip, npm). Caches persist across resets for fast reinstalls. Sandboxes can reach each other by name via /etc/hosts entries auto-injected when networking is available.
Profiles
Configure per-sandbox-name resources in SANDBOX_PROFILES at the top of the server:
SANDBOX_PROFILES = {
"ml": {"cpus": 4, "memory": "2G"},
"build": {"cpus": 4, "memory": "1G"},
"nested": {"cpus": 2, "memory": "1G", "virtualization": True},
}The virtualization flag enables nested virtualization (--virtualization). GPU/Metal passthrough is not supported by Apple Containers — the kernel has CONFIG_DRM_VIRTIO_GPU disabled and the Swift framework doesn't use VZVirtioGraphicsDeviceConfiguration.
Child sandboxes
Sandboxes can spawn child sandboxes, controlled by SPAWN_POLICIES at the top of the server. Policies define per-parent limits: max concurrent children, lifetime spawn count, CPU/memory budgets, allowed images, and TTL. Unlisted sandbox names cannot spawn.
Children are lightweight — they skip cache volumes and get their own isolated workspace. They're auto-destroyed when their TTL expires or their parent is reset/destroyed.
Setting child_can_spawn: True in a policy allows children to spawn their own children (grandchildren), up to a depth of _MAX_SPAWN_GENERATION (default 2). Grandchild policies are derived automatically — halved concurrency/budget limits, no further sub-spawning. A tree-wide budget check ensures the root sandbox's CPU/memory envelope is never exceeded regardless of spawn depth. This is off by default and not recommended for most use cases.
In-container API (sandbox-ctl)
When a sandbox has a spawn policy with inject_ctl: True (the default), the server mounts a UDS socket and the sandbox-ctl binary into the VM. Set inject_ctl: False to skip injection for sandboxes that don't need in-VM sub-launching. Code running inside the VM can then spawn/manage sibling containers:
sandbox-ctl ping # verify connection
sandbox-ctl spawn --image mcp-dev --cpus 1 --memory 256M # create child
sandbox-ctl list # show children
sandbox-ctl exec <child> -- echo hello # run in child
sandbox-ctl destroy <child> # tear down
sandbox-ctl run -- echo test # ephemeral: spawn + exec + destroyCommunication uses NDJSON over the mounted socket (/run/sandbox-ctl.sock). The host-side SandboxCtlServer handles requests and delegates to SandboxManager.
State persistence
Sandbox-to-container mappings are saved to ~/.local/state/sandbox-mcp/state.json (schema v2). On restart, the server reconnects to any still-running containers from the previous session. Expired children are cleaned up on reconnect.
Tools (35)
Core
Tool | Description |
| Run a shell command (~60ms) |
| Execute Python code |
| Write a file to the sandbox |
| Read a file from the sandbox |
| Write multiple files in one transfer |
| Install packages via apk |
| Manage persistent environment variables |
Process management
Tool | Description |
| Run a command in the background |
| Read output from a background process |
| Kill a background process |
Sandbox lifecycle
Tool | Description |
| Show pool and sandbox info |
| Quick liveness/disk/memory check across all sandboxes |
| Show CPU/memory/disk usage for one sandbox |
| Destroy and recreate (clean state) |
| List all active sandboxes |
| Permanently kill a sandbox |
| Clone a running sandbox to a new name |
| Show recent command audit log |
File transfer
Tool | Description |
| Copy files from host into sandbox |
| Copy files from sandbox to host |
| Clone a git repo (with optional auth token) |
| Watch and live-sync a host directory |
| Stop a running sync job |
Snapshots & images
Tool | Description |
| Save sandbox state as a reusable image |
| Boot from a saved snapshot |
| List available snapshots |
| Delete a saved snapshot image |
| Build a container image from a Containerfile |
| List all available container images |
Networking
Tool | Description |
| Forward a sandbox port to localhost (TCP proxy) |
| Stop a port forward |
| Show IPs and connectivity between sandboxes |
Child sandboxes
Tool | Description |
| Spawn a child sandbox under a parent |
| List child sandboxes of a parent |
| Destroy a child sandbox |
Files
File | Description |
| Sandbox class, SandboxManager, MCP tool definitions |
| In-container CLI for spawning sibling sandboxes (Go) |
| uv/hatchling packaging, entry point |
| Alpine 3.23 dev image with Python, Node, Go, Rust |
| pytest test suite |
Customization
Edit constants at the top of sandbox_mcp_server.py:
Constant | Default | Description |
|
| Container image for new sandboxes |
|
| Default CPU cores per sandbox |
|
| Default memory per sandbox |
|
| Seconds before auto-destroying idle sandboxes |
|
| Default command timeout in seconds |
|
| Max output bytes per command |
|
| Per-sandbox child spawn limits and permissions |
|
| Maximum spawn depth (root → child → grandchild) |
Testing
uv run pytest tests/ -vCI
Tests run on Python 3.11, 3.12, and 3.13 via GitHub Actions. Pre-push:
uv run pytest tests/ -q && python3 -m compileall sandbox_mcp_server.py testsAvailable Tools
35 toolsbatch_writeA
Write multiple files to the sandbox in a single operation. Much faster than multiple write_file calls for scaffolding projects.
Args: files: JSON object mapping absolute paths to file contents. Example: {"/workspace/main.py": "print('hi')", "/workspace/config.yml": "port: 8080"} sandbox: Named sandbox (default "default")
Returns: Confirmation with file count and timing.
Inputs: files (required), sandbox. Returns: result
bgA
Start a background process in the sandbox (e.g., a dev server).
Args: command: Command to run in background (e.g., "python3 -m http.server 8000") name: Optional friendly name for the process (auto-generated if empty) workdir: Working directory (default: /workspace) sandbox: Named sandbox to use (default "default")
Returns: Process ID and name for use with logs/kill.
Inputs: command (required), name, workdir, sandbox. Returns: result
build_imageA
Build a container image from a Containerfile (Dockerfile syntax). The image can then be used with restore or as the default image.
Args: name: Name/tag for the built image (e.g., "my-ml-env", "node-app"). containerfile: Containerfile content (Dockerfile syntax). Example: "FROM alpine:3.23\nRUN apk add --no-cache python3"
Returns: Confirmation with build time.
Inputs: name (required), containerfile (required). Returns: result
childrenC
List all child sandboxes of a parent.
Args: parent: Name of the parent sandbox.
Returns: List of children with status, or indication that none exist.
Inputs: parent. Returns: result
cloneA
Clone a running sandbox to a new name. Copies the full filesystem (except /workspace) to a fresh sandbox. Faster than snapshot+restore since it skips image build.
Args: source: Name of the sandbox to clone from. target: Name for the new cloned sandbox.
Returns: Confirmation with timing.
Inputs: source (required), target (required). Returns: result
delete_snapshotA
Delete a saved snapshot image. Frees disk space.
Args: snapshot_name: Name of the snapshot to delete (from list_snapshots).
Returns: Confirmation or error.
Inputs: snapshot_name (required). Returns: result
destroyA
Permanently destroy a named sandbox without recreating it. Unlike reset (which destroys and reboots), this just kills it. Workspace volume is preserved and will be reattached if the sandbox is recreated.
Args: sandbox: Name of the sandbox to destroy.
Returns: Confirmation or error.
Inputs: sandbox (required). Returns: result
destroy_childB
Destroy a child sandbox. The child's parent must have a spawn policy.
Args: name: Name of the child sandbox to destroy.
Returns: Confirmation or error.
Inputs: name (required). Returns: result
downloadB
Copy a file or directory from the sandbox to the host.
Args: sandbox_path: Path inside the sandbox to download. local_path: Absolute destination path on the host. sandbox: Named sandbox to use (default "default")
Returns: Confirmation with transferred size.
Inputs: sandbox_path (required), local_path (required), sandbox. Returns: result
envA
Manage persistent environment variables in a sandbox. Variables persist across all commands (sourced from /etc/profile.d/mcp-env.sh).
Args: action: "set", "unset", or "list" (default: "list") key: Variable name (required for set/unset) value: Variable value (required for set) sandbox: Named sandbox (default "default")
Returns: Current env vars or confirmation.
Inputs: action, key, value, sandbox. Returns: result
execA
Execute a shell command in the sandbox.
Args: command: Shell command to run (e.g., "ls -la", "echo hello", "cat /etc/os-release") timeout: Max seconds to wait (default 30) workdir: Working directory inside the sandbox (default /workspace) stdin: Optional input to pipe into the command's stdin sandbox: Named sandbox to use (default "default")
Returns: Command output with stdout, stderr, exit code, and execution time.
Inputs: command (required), timeout, workdir, stdin, +1 more. Returns: result
exposeA
Forward a sandbox port to localhost via TCP proxy.
Creates a local listener that proxies connections into the sandbox via container exec.
Args: port: Port number inside the sandbox (e.g., 8000, 3000, 5432). host_port: Port to listen on locally (default: same as sandbox port). sandbox: Named sandbox to expose (default "default").
Returns: Connection URL if successful, or error message.
Inputs: port (required), host_port, sandbox. Returns: result
git_cloneA
Clone a git repository into the sandbox.
Args: repo: Repository URL (e.g., "https://github.com/user/repo.git") branch: Branch to clone (default: repo's default branch) token: Optional auth token for private repos (injected securely, not in URL or history) path: Parent directory for clone (default: /workspace) shallow: If True, clone with --depth 1 for speed (default: True) sandbox: Named sandbox to use (default "default")
Returns: Clone result with repo info.
Inputs: repo (required), branch, token, path, +2 more. Returns: result
healthA
Quick health check across all sandboxes: shell liveness, disk/memory pressure, uptime. Useful for diagnosing issues when commands fail or sandboxes become unresponsive.
Returns: Per-sandbox health summary with warnings for any issues detected.
Inputs: no named parameters. Returns: result
historyA
Show recent command history for a sandbox. Tracks the last 100 commands with exit codes and timing.
Args: limit: Number of recent commands to show (default: 20) sandbox: Named sandbox (default "default")
Returns: Command history with timing and exit codes.
Inputs: limit, sandbox. Returns: result
imagesA
List all available container images (base images + snapshots + custom builds).
Returns: Image listing with names and sizes.
Inputs: no named parameters. Returns: result
installA
Install packages in the sandbox using apk (Alpine package manager).
Args: packages: Space-separated package names (e.g., "python3 nodejs git curl") sandbox: Named sandbox to use (default "default")
Returns: Installation result.
Inputs: packages (required), sandbox. Returns: result
killA
Kill a background process.
Args: name: Process name/ID from bg. sandbox: Named sandbox to use (default "default")
Returns: Confirmation.
Inputs: name (required), sandbox. Returns: result
list_allB
List all active sandboxes with their status.
Returns: Table of sandbox names, containers, shell status, and idle time.
Inputs: no named parameters. Returns: result
list_snapshotsA
List all available sandbox snapshots.
Returns: List of snapshot names, or "none" if no snapshots exist.
Inputs: no named parameters. Returns: result
logsA
Read output from a background process.
Args: name: Process name/ID from bg. tail: Number of lines to show from end (default: 50, use 0 for all). sandbox: Named sandbox to use (default "default")
Returns: Process output (stdout + stderr combined).
Inputs: name (required), tail, sandbox. Returns: result
network_infoA
Show network information for all sandboxes including IP addresses and pairwise connectivity. Useful for multi-sandbox workflows where services need to communicate.
Returns: Network info with IPs and connectivity status.
Inputs: no named parameters. Returns: result
pythonA
Execute Python code in the sandbox (python3 is pre-installed in the default mcp-dev image).
Args: code: Python code to execute. timeout: Max seconds to wait (default 30). sandbox: Named sandbox to use (default "default")
Returns: Script output with stdout, stderr, exit code, and execution time.
Inputs: code (required), timeout, sandbox. Returns: result
read_fileA
Read a file from the sandbox.
Args: path: Absolute path to read (e.g., /workspace/output.txt) sandbox: Named sandbox to use (default "default")
Returns: File contents.
Inputs: path (required), sandbox. Returns: result
resetA
Destroy the current sandbox and create a fresh one. Use this when you want a clean environment.
Args: wipe_workspace: If True, also delete all files in /workspace. If False (default), /workspace files persist across resets. sandbox: Named sandbox to reset (default "default")
Returns: Confirmation of the new sandbox.
Inputs: wipe_workspace, sandbox. Returns: result
restoreA
Destroy the current sandbox and boot from a saved snapshot. Workspace files are preserved (they live on a separate volume).
Args: snapshot_name: Name of the snapshot to restore (from list_snapshots) sandbox: Named sandbox to restore into (default "default")
Returns: Confirmation or error.
Inputs: snapshot_name (required), sandbox. Returns: result
snapshotA
Save the current sandbox state as a reusable snapshot image. The snapshot captures installed packages and system state (not /workspace files, which live on a separate persistent volume).
Args: snapshot_name: Name for the snapshot (e.g., "with-pytorch", "ml-env") sandbox: Named sandbox to snapshot (default "default")
Returns: Confirmation or error.
Inputs: snapshot_name (required), sandbox. Returns: result
spawnA
Spawn a child sandbox under a parent sandbox. The parent must have a spawn policy configured in SPAWN_POLICIES. Children have restricted capabilities (no clone/snapshot/restore/reset).
Args: image: Container image for child (default: first allowed image from parent's policy). parent: Name of the parent sandbox (must have spawn policy). name: Name for the child sandbox (auto-generated if empty). cpus: CPU cores for child (0 = use policy default, clamped to policy ceiling). memory: Memory for child e.g. "512M" (empty = use policy default, clamped to ceiling).
Returns: Child sandbox info or error.
Inputs: image, parent, name, cpus, +1 more. Returns: result
statsB
Show resource usage (CPU, memory, disk) of the active sandbox.
Args: sandbox: Named sandbox to check (default "default")
Returns: Current resource usage statistics.
Inputs: sandbox. Returns: result
statusA
Show current sandbox and pool status.
Returns: Status information including active sandboxes, pool size, image, and network.
Inputs: no named parameters. Returns: result
sync_startA
Start watching a local host directory and live-syncing changes into the sandbox. Does an initial full sync, then polls for changes every second. Ignores .git, node_modules, pycache, .venv, .DS_Store.
Args: local_dir: Absolute path on the host to watch. sandbox_dir: Destination directory in the sandbox (default: /workspace). sandbox: Named sandbox to sync to (default "default")
Returns: Sync job ID and initial sync stats.
Inputs: local_dir (required), sandbox_dir, sandbox. Returns: result
sync_stopA
Stop a running file sync job.
Args: job_id: The sync job ID from sync_start.
Returns: Confirmation with total files synced.
Inputs: job_id (required). Returns: result
unexposeA
Stop a port forward previously created by expose.
Args: port: The localhost port to stop forwarding.
Returns: Confirmation with connection stats.
Inputs: port (required). Returns: result
uploadA
Copy a file or directory from the host into the sandbox.
Args: local_path: Absolute path on the host (file or directory). sandbox_path: Destination path inside the sandbox (default: /workspace). sandbox: Named sandbox to use (default "default")
Returns: Confirmation with transferred file count and size.
Inputs: local_path (required), sandbox_path, sandbox. Returns: result
write_fileA
Write content to a file in the sandbox.
Args: path: Absolute path in the sandbox (e.g., /workspace/script.py) content: File content to write. sandbox: Named sandbox to use (default "default")
Returns: Confirmation with file path and size.
Inputs: path (required), content (required), sandbox. Returns: result
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 35 tools
Each tool has a clearly distinct purpose, from file operations to process management, sandbox lifecycle, networking, and snapshots. There is no ambiguity between tools like exec, python, bg, or between destroy and reset.
All tool names follow a consistent lowercase snake_case convention, with verbs typically preceding nouns (e.g., git_clone, batch_write, sync_start). Exceptions like 'expose' and 'kill' are still clear and fit the verb-first pattern.
With 35 tools, the server is comprehensive but slightly large. It covers many aspects of sandbox management, but a few tools like 'sync_start' and 'sync_stop' or 'expose' and 'unexpose' could be combined, reducing count without loss of clarity.
The tool set covers core sandbox operations well, but notable gaps exist: no explicit sandbox creation tool (only reset or spawn), no tool for listing directory contents or deleting files, and no detailed configuration retrieval. Users may need to rely on exec for basic file management.
Related MCP Connectors
Cloud Linux VMs for your agent: run code, Docker, files and HTTPS previews in a Sandboxer microVM.
Linux microVMs for AI agents: run commands, read and write files, pause and resume.
Linux VMs for AI agents: create VMs, run commands, edit files and open preview URLs.
Linux sandboxes for AI agents: run commands and Python or JS, files, ports, pause. E2B-compatible.
Related MCP Servers
- AlicenseAqualityDmaintenanceRun AI agents in VM-isolated sandboxes on your Mac.151MIT
- AlicenseAqualityCmaintenanceProvides agents with real Linux VMs to run commands, manage files, expose ports, and track costs, all through an ephemeral sandbox service.11MIT
- FlicenseNot gradedqualityAmaintenanceLets AI agents manage local virtual machines: create macOS and Linux VMs on Apple silicon and WSL distros on Windows, start/stop, clone, back up, and run commands inside them.4,068-

Runtimeofficial
AlicenseNot gradedqualityBmaintenanceLinux sandboxes for AI agents, each a Firecracker microVM. Run code, keep files, pause and wake with memory kept, snapshot and fork.2Apache 2.0