SandboxRunner
Click on "Install 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., "@SandboxRunnerRun Python code: print('Hello, world!')"
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.
SandboxRunner ๐ณ
SandboxRunner is a custom Model Context Protocol (MCP) server that enables AI assistants and MCP-compatible clients to securely execute Python and C++ code snippets inside disposable, isolated Docker containers โ and receive back structured results (stdout, stderr, exit code, and timing) in real time.
Built to understand MCP server design, Docker-based process isolation, and security-boundary thinking from the ground up.
Table of Contents
Related MCP server: Netmind Code Interpreter
Features
โ Python execution โ runs snippets inside
python:3.12-slimโ C++ execution โ two-stage compile (
g++ -std=c++17 -O2) + run, usinggcc:14โ Strong isolation per run:
No network access (
--network none)Hard memory cap (default
256m)Hard CPU cap (default
0.5cores)Read-only root filesystem with a temporary scratch-only mount
noexectmpfs for/tmpContainers are ephemeral โ deleted after every run
โ Independent timeout enforcement โ a hung snippet cannot hang the MCP server; the container is force-killed on timeout
โ Output size capping โ stdout/stderr truncated at 100 KB with a clear marker
โ Distinct compile vs. runtime errors for C++ โ compiler errors are surfaced separately from runtime crashes
โ Local execution history โ every run is logged to a local SQLite database and queryable via MCP
โ Actionable Docker errors โ clear error message if Docker is not running, instead of a silent hang
โ All tunables in one place โ
config.pyis the single source of truth for limits, images, and settings
Architecture
MCP Client โโ(stdio / sse)โโโถ SandboxRunner (FastMCP)
โ
โผ
execution.py (orchestration)
โ
โโโโโโโโโโโโโโโดโโโโโโโโโโโโโโ
โผ โผ
Docker (Python) Docker (C++)
python:3.12-slim gcc:14 container
--network none --network none
--memory 256m --memory 256m
--cpus 0.5 --cpus 0.5
--read-only Stage 1: compile (rw /scratch)
Stage 2: run (ro /scratch)
โ
โผ
database.py โ sandbox_history.db (SQLite)Per-execution flow (run_code)
Validates input โ language, code size, timeout ceiling
Writes code to a temporary host directory
Mounts that directory into a fresh Docker container as
/scratchPython: runs
python /scratch/snippet.pydirectlyC++: compiles to
/scratch/a.out(read-write mount), then runs the binary (read-only mount) in a second container โ compile errors are returned distinctly from runtime errorsEnforces timeout at the server level; kills the container if exceeded
Captures and truncates stdout/stderr
Logs run metadata to SQLite
Returns a structured result to the MCP client
Requirements
Python โฅ 3.12
Docker Desktop or Docker Engine โ must be installed and running
Docker images (pre-pull recommended):
python:3.12-slimgcc:14
Python Dependencies
Package | Purpose |
| Official MCP SDK (FastMCP server + CLI) |
| Docker SDK โ container orchestration |
Dev only:
Package | Purpose |
| Test runner |
| Async test support |
Installation
# 1. Clone the repository
git clone https://github.com/your-username/sandbox-runner.git
cd sandbox-runner
# 2. Ensure Docker is running
docker ps
# 3. Install dependencies and create the virtual environment
uv sync
# 4. Pre-pull the Docker images (avoids slow cold start on first run)
docker pull python:3.12-slim
docker pull gcc:14The sandbox-runner console script is installed automatically via [project.scripts] in pyproject.toml.
Configuration
All tunables live in src/sandbox_runner/config.py. No environment variables are required beyond the optional transport flag.
Setting | Default | Description |
|
| Default execution timeout |
|
| Hard ceiling โ cannot be exceeded by callers |
|
| Per-container memory cap |
|
| Per-container CPU share (in cores) |
|
| Maximum allowed snippet size |
|
| Output truncation threshold |
|
| SQLite file for execution history |
|
| Default rows returned by history tool |
To add a new language, add an entry to SUPPORTED_LANGUAGES in config.py with an image, run_cmd, and optionally compile_cmd / source_file for compiled languages.
MCP Tools
Tool | Description | Inputs | Outputs |
| Execute a code snippet in an isolated container |
|
|
| List available languages and Docker images | โ |
|
| Retrieve recent run records |
|
|
status values: success ยท error ยท timeout ยท compile_error (C++ only)
Example run_code response:
{
"status": "success",
"exit_code": 0,
"stdout": "The sum of elements is: 15\n",
"stderr": "",
"duration_ms": 1823.47,
"language": "cpp"
}Isolation & Resource Limits
Each run is sandboxed with the following Docker constraints:
Constraint | Value | Effect |
| Enforced | No outbound or inbound network access |
| Configurable | Hard memory ceiling per container |
| Configurable | CPU share cap |
| Always on | Root filesystem is immutable |
|
| Small, non-executable temp space |
| Always on | Container is deleted after each run |
Timeout kill | Server-level | Server kills container if it exceeds timeout |
โ ๏ธ This uses Docker-level isolation โ suitable for personal/local use. It is not a hardened multi-tenant sandbox (e.g. gVisor, Firecracker) and is not intended for running untrusted third-party code.
Execution History
Every run is stored in a local SQLite database (sandbox_history.db):
CREATE TABLE IF NOT EXISTS runs (
id INTEGER PRIMARY KEY AUTOINCREMENT,
timestamp REAL NOT NULL,
language TEXT NOT NULL,
code_snippet TEXT NOT NULL, -- first 500 chars only
status TEXT NOT NULL,
exit_code INTEGER,
duration_ms REAL NOT NULL,
stdout_size INTEGER NOT NULL DEFAULT 0,
stderr_size INTEGER NOT NULL DEFAULT 0
);Only the first 500 characters of each snippet are persisted as a preview.
stdout_size/stderr_sizestore byte counts, not the full content.Timestamps are returned as ISO 8601 UTC strings via the
get_execution_historytool.
Usage
Registering with an MCP Client
Add SandboxRunner to your MCP client's configuration. Example for Claude Desktop (claude_desktop_config.json):
{
"mcpServers": {
"sandbox-runner": {
"command": "uv",
"args": [
"--directory",
"/absolute/path/to/sandbox-runner",
"run",
"sandbox-runner"
]
}
}
}Replace
/absolute/path/to/sandbox-runnerwith your actual cloned directory path.
On Windows:C:\\Users\\YourName\\path\\to\\sandbox-runner
Restart the MCP client after saving the config. The three tools will become available immediately.
Running Standalone
# Start with stdio transport (default โ for MCP clients like Claude Desktop)
uv run sandbox-runner
# Start with SSE transport (for web-based or HTTP MCP clients)
uv run sandbox-runner --transport sse
# View CLI help
uv run sandbox-runner --helpProject Structure
sandbox-runner/
โโโ src/
โ โโโ sandbox_runner/
โ โโโ __init__.py # Package version
โ โโโ config.py # All tunables โ limits, images, DB path
โ โโโ database.py # SQLite connection, record_run, fetch_history
โ โโโ execution.py # Docker orchestration, validation, truncation
โ โโโ main.py # CLI entrypoint (argparse + transport)
โ โโโ server.py # FastMCP server + tool definitions
โโโ tests/
โ โโโ test_execution.py # Input validation + mocked Docker execution tests
โ โโโ test_server.py # Mocked MCP tool-level tests
โโโ pyproject.toml # Project metadata, deps, build config
โโโ uv.lock # Locked dependency tree
โโโ .python-version # Pinned Python version
โโโ sandbox_history.db # SQLite history (auto-created at runtime)
โโโ README.mdTesting
The test suite uses mocked Docker calls โ Docker does not need to be running to run the tests.
uv run pytestCurrent coverage:
test_execution.pyValid input passes without errors
Unsupported language raises
ValueErrorEmpty code raises
ValueErrorOversized code raises
ValueErrorTimeout exceeding max raises
ValueErrorMocked end-to-end Python execution โ asserts
status == "success"and correct stdout
test_server.pyrun_codesuccess path โ verifies result format and DB logging callrun_codeinvalid language โ verifies error response and that DB is not writtenlist_supported_languagesโ returns entries for bothpythonandcppget_execution_historyโ timestamps formatted as ISO 8601 strings
Known Limitations
Docker must be running. The server returns a clear error if the Docker daemon is unreachable โ no silent hangs.
Docker-level isolation only. Not a hardened cloud-grade sandbox. Designed for single-user, local use.
No multi-tenancy. No auth, no rate limiting โ assumes a single trusted operator.
Fixed resource limits by default. 256 MB / 0.5 CPU / 10s default timeout may be restrictive for heavy compute workloads.
History stores only snippet previews. Full code content is not persisted; only the first 500 characters are stored.
Contributing
Contributions are welcome!
Fork the repo and create a feature branch
Run
uv run pytestand ensure all tests passKeep new tunables in
config.pyโ avoid hardcoding values elsewhereOpen a Pull Request with a clear description of the change and its motivation
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Latest Blog Posts
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/huzayfaSiddique/sandbox_runner'
If you have feedback or need assistance with the MCP directory API, please join our Discord server