Run untrusted Python and JavaScript code in isolated WebAssembly sandboxes
open sourceApache-2.0self-hostablefreeMCP
Capsule is an open source runtime, written in Rust, that runs untrusted code such as AI agents' tasks inside WebAssembly sandboxes. You mark Python functions with a @task decorator or wrap TypeScript and JavaScript functions with task(), and each task runs in its own sandbox with CPU limits through Wasm fuel metering, a memory cap, a timeout and automatic retries, returning a JSON envelope with the result and execution metrics. Tasks have no network or file access unless you allow hosts and directories (read-only or read-write). Run tasks with the capsule CLI or from your own code with run(), or give an agent the Capsule MCP server, whose execute_python and execute_javascript tools run code in a fresh sandbox each time. It's Apache-2.0 licensed and ships on PyPI as capsule-run and on npm as @capsule-run/cli, @capsule-run/sdk and @capsule-run/mcp-server.
Problems it solves
- run code an AI agent wrote without risking my machine
- sandbox untrusted Python code with CPU, memory and time limits
- let my agent execute Python or JavaScript safely through MCP
- a lightweight code sandbox without Docker or VMs
- isolate each agent task so a failure doesn't take down the rest
- block network and file access for untrusted code except an allowlist
- run user-submitted JavaScript in a WebAssembly sandbox
- a code interpreter tool for an LLM agent that runs locally
Features
- @task decorator for Python and task() wrapper for TypeScript/JavaScript
- a WebAssembly sandbox per task
- CPU limits through Wasm fuel (LOW, MEDIUM, HIGH or custom)
- memory limits, timeouts and automatic retries
- JSON result envelope with duration, retries, fuel and RAM used
- outbound HTTP only to allowed hosts
- file access only to allowed directories, read-only or read-write
- capsule run CLI
- run() to execute sandboxed tasks from host code
- MCP server with execute_python and execute_javascript tools
View 1 more
- Python and TypeScript adapters
Limitations
- Python packages with C extensions need a wasm32-wasi wheel, so numpy and pandas don't work inside the sandbox1
- Each MCP execution starts from a clean sandbox with no state shared between calls2
- Standard Python networking libraries don't work inside the MCP server's sandbox2
Capabilities
| Has a command line tool | plan not known |
|---|---|
| Has an MCP server | plan not known |
| Has official SDKs | plan not known |
Alternatives
The same job
These do what Capsule does.
- Vercel Sandbox Run agent workloads in isolated sandboxes
- E2B The AI agent cloud: an isolated sandbox machine for every agent session
- Modal Pay per second for GPUs and CPUs
- Wasmer Fast and lightweight sandboxes for your apps and AI agents
- Sandscale Isolated cloud sandboxes, workspaces and build machines for AI agents
- CodeSandbox Instant cloud development environments and sandboxes built for scale
