Core Concepts
This page explains the key concepts in Eryx and how they work together.
Sandbox
A Sandbox is the main entry point for executing Python code in isolation. Each sandbox:
- Contains a WebAssembly instance of CPython 3.14
- Has isolated memory and no access to host resources by default
- Can be configured with callbacks, resource limits, and network access
- Is designed for one-off executions where state doesn’t persist
Use sandboxes when each execution should start with a clean slate.
Sessions
A Session wraps a sandbox and maintains Python state across multiple executions:
- Variables, functions, and classes persist between executions
- Useful for REPL-style interfaces and incremental computation
- Can optionally include a virtual filesystem for file persistence
- More efficient than creating new sandboxes for each execution
Use sessions when you need stateful, interactive Python execution.
Callbacks
Callbacks are functions exposed from the host that sandboxed Python can call:
- Provide controlled access to host capabilities (database, API calls, etc.)
- Are async from both host and sandbox perspectives
- Can be strongly typed (Rust) or dynamically defined (Python)
- Allow sandboxed code to request information without direct access
Callbacks are the primary way sandboxed code interacts with the outside world.
MCP Integration
MCP (Model Context Protocol) tools can be bridged into the sandbox as callbacks:
- Automatically discovers MCP servers from IDE configs (Claude Code, Cursor, VS Code, Zed, Windsurf, Codex, Gemini)
- Exposes tools as async functions under
mcp.<server>.<tool>namespaces - Only stdio-type servers are supported
MCP integration lets sandboxed code access external tool servers without any custom callback code.
Resource Limits
Resource Limits control what sandboxed code can do:
- Execution timeout — Maximum time for code to run
- Memory limits — Maximum memory usage
- Callback limits — Maximum number of callback invocations
- Callback timeout — Maximum time for a single callback
Resource limits prevent runaway code from consuming excessive resources.
Networking
Networking is disabled by default but can be enabled with policies:
- Host filtering — Allow/block specific domains with wildcard patterns
- Connection limits — Maximum concurrent connections
- Timeouts — Connection and I/O timeouts
- TLS support — Full HTTPS support with custom certificates
Network access is controlled by the host, not the sandboxed code.
Secrets
Secrets provide secure handling of sensitive values like API keys:
- Python code sees opaque placeholders, never real values
- Real values are only substituted when making HTTP requests to authorized hosts
- Placeholders are automatically scrubbed from stdout, stderr, and file writes
- Each secret can be restricted to specific hosts
Secrets prevent untrusted code from exfiltrating sensitive credentials.
WebAssembly & WASI
Eryx uses WebAssembly (Wasm) and WASI for sandboxing:
- WebAssembly provides memory isolation and controlled execution
- WASI (WebAssembly System Interface) provides limited system access
- Wasmtime is the runtime that executes the Wasm code
- Component Model enables the callback mechanism
You don’t need to understand these details to use Eryx, but they provide strong security guarantees.
Pre-compilation
The embedded feature includes pre-compiled Wasm for fast startup:
- Python interpreter initialization (~450ms) is done at build time
- Sandbox creation is reduced from ~650ms to ~16ms (41x faster)
- The pre-compiled binary is embedded in your application
- Trade-off: adds ~32MB to your binary size
Packages
Eryx supports loading Python packages at runtime:
.whlfiles (standard Python wheels).tar.gz/.tgzfiles (used by wasi-wheels project)- Native extensions compiled for WASI
- Packages are loaded per-sandbox or via
SandboxFactoryfor reuse
Volume Mounts
Volume Mounts allow controlled access to host filesystem directories:
- Mount host directories at specific paths inside the sandbox
- Optional read-only enforcement
- Uses capability-based security (cap-std)
- Sandboxed code cannot access paths outside the mounted directories
Volume mounts complement the VFS by providing access to real host files when needed.
Architecture Overview
┌─────────────────────────────────────────────┐
│ Your Application (Host) │
│ ┌─────────────────────────────────────┐ │
│ │ Eryx Sandbox │ │
│ │ ┌───────────────────────────────┐ │ │
│ │ │ WebAssembly Instance │ │ │
│ │ │ ┌─────────────────────────┐ │ │ │
│ │ │ │ CPython 3.14 │ │ │ │
│ │ │ │ (Sandboxed Code) │ │ │ │
│ │ │ └─────────────────────────┘ │ │ │
│ │ │ ↑ │ │ │
│ │ │ │ Callbacks │ │ │
│ │ │ ↓ │ │ │
│ │ └───────────────────────────────┘ │ │
│ │ (Wasmtime Runtime) │ │
│ └─────────────────────────────────────┘ │
└─────────────────────────────────────────────┘
Sandbox vs Session Comparison
| Feature | Sandbox | Session |
|---|---|---|
| State persistence | No — fresh each execute() | Yes — variables persist |
| Virtual filesystem | No | Optional |
| Use case | One-off execution | REPL, multi-step workflows |
| Isolation | Complete per-call | Complete from host |
| Performance | Moderate overhead | Lower overhead after warmup |
Security Model
Eryx provides defense-in-depth security:
- Process-level isolation — Wasm provides memory isolation
- Capability-based security — Only explicitly granted capabilities are available
- Resource limits — Prevent resource exhaustion
- Network policies — Control which hosts can be accessed
- No filesystem access — Unless explicitly enabled with VFS or volume mounts
- Secrets isolation — Sensitive values are never directly accessible to sandboxed code
This makes Eryx suitable for running untrusted Python code.
Next Steps
- Sandboxes Guide - Detailed sandbox configuration
- Callbacks Guide - Implementing callbacks
- MCP Integration - Connecting MCP tool servers
- Sessions Guide - Working with sessions
- Resource Limits - Configuring limits
- Secrets Guide - Secure secrets management
- CLI Guide - Command-line interface