mcp-secure-sandbox
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
Secure Python Sandbox & Data Validator MCP Server
A production-ready, highly secure, and containerized Model Context Protocol (MCP) server built in Python using FastMCP. This server isolates code executions within a sandboxed environment, offers automated data validation (JSON Schema and CSV structures), and maintains state snapshots to support deterministic testing pipelines.
๐๏ธ Architecture & Isolation Model
This server implements four distinct layers of security to ensure that code generated by LLMs cannot execute destructive operations or compromise the host system.
graph TD
Client[Client e.g., Claude Desktop] -->|MCP JSON-RPC| Server[FastMCP Server Process]
Server -->|Tool: run_sandbox_code| AST{AST Safety Checker}
AST -->|Safety Violations| Fail[Reject & return Traceback]
AST -->|Safe AST| Subprocess[Spawn Python Subprocess]
Subprocess -->|Preamble Injection| Closure[Intercept builtins.open]
Closure -->|Access within Workspace| Execute[Run Script]
Closure -->|Access outside Workspace| Block[PermissionError Blocked]
Execute -->|Capture stdout/stderr/time| Server
Server -->|Response| ClientThe 4 Layers of Defense:
Container Isolation (Docker): The server runs as a non-root system user (
mcpuser) inside a minimalpython:3.12-slimcontainer, ensuring zero access to the host's root filesystem or processes.Static AST Analysis: Prior to execution, code is parsed into an Abstract Syntax Tree (AST). The AST visitor blocks dangerous built-in functions (
exec,eval), double-underscore metadata attributes (__class__,__subclasses__), and unapproved imports (e.g.os,sys,subprocess,socket).Subprocess Isolation: Code is executed inside a spawned Python subprocess rather than the server's parent process. This isolates the memory context, manages clean execution time-outs, and handles crashes without crashing the MCP server.
Closure-based Path Interception: The server injects a sandbox preamble that overrides python's built-in
open()function using a closure factory. This factory validates all file paths and blocks directory traversal attempts (using..or absolute paths outside the workspace) with aPermissionError.
Related MCP server: Docker MCP Server
๐ ๏ธ MCP Specifications
Tools
Tool Name | Parameters | Description |
|
| Validates and executes code in the isolated workspace. |
|
| Validates JSON payloads against predefined or custom schemas. |
|
| Enforces column headers and datatype rules on CSV data. |
|
| Saves a snapshot of the workspace (files, hashes, metadata). |
|
| Reverts the workspace filesystem to a saved snapshot. |
| None | Lists all saved snapshots chronologically. |
|
| Permanently deletes a saved snapshot file. |
| None | Returns resource usage (memory, CPU) and tool execution statistics. |
Resources
sandbox://status: Returns JSON data outlining active configurations, workspaces, and snapshot counts.sandbox://logs: Retrieves the last 100 execution traces in memory (timestamp, log level, messages, and performance times).sandbox://schemas: Lists all pre-registered validation schemas (config,user,dataset).
Prompts
generate_secure_script: Prompts the LLM client to write a Python script complying with the AST safety and workspace file constraints.diagnose_validation_error: Diagnoses schema validation errors and generates corrected JSON payloads.
๐ Installation & Setup
Prerequisites
Python 3.12+ (or Docker installed on the host machine)
Python virtual environment tools (
venv)
Local Setup & Testing
Clone or copy the repository files.
Initialize virtual environment and install requirements:
python -m venv .venv .venv/Scripts/activate # On Windows source .venv/bin/activate # On Linux/macOS pip install -r requirements.txtRun the unit and integration tests:
python -m pytest -vvStart the server locally in stdio transport mode:
python -m src.server
Containerized Sandbox Setup (Docker)
To build and run the secure container using Docker:
# Build the Docker image
docker build -t mcp-secure-sandbox .
# Run the container in interactive stdio mode
docker run -i --rm -v "$(pwd)/sandbox_workspace:/sandbox/workspace" mcp-secure-sandboxUsing Docker Compose:
# Start the container with mounted volumes
docker-compose up -dThe workspace files are persisted locally in the./sandbox_workspace folder, and snapshots are saved in the ./sandbox_snapshots folder. Both paths are automatically synchronized inside the container.
โ๏ธ Client Integration (Claude Desktop Config)
Add the following block to your Claude Desktop configuration file (typically located at %APPDATA%\Claude\claude_desktop_config.json on Windows or ~/Library/Application Support/Claude/claude_desktop_config.json on macOS):
{
"mcpServers": {
"secure-sandbox": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"-v",
"E:/mcp-secure-sandbox/sandbox_workspace:/sandbox/workspace",
"-v",
"E:/mcp-secure-sandbox/sandbox_snapshots:/sandbox/snapshots",
"mcp-secure-sandbox"
]
}
}
}Verify that the local folder paths mounted in the-v args exist on your host and are formatted correctly as absolute paths.
๐ฆ State Snapshot Details
The snapshot engine saves the state of the workspace inside JSON records. A snapshot contains:
Snapshot Metadata: UUID, ISO UTC timestamp, and descriptions.
File Registry: Maps relative paths of all files in
/sandbox/workspaceto:File size (bytes)
Modification timestamp (
mtime)SHA-256 hash of contents
Content payload (UTF-8 string for text files, Base64 encoding for binaries)
When restore_state_snapshot is triggered:
It compares the current workspace state with the snapshot registry.
Files not present in the snapshot registry are deleted.
Modified files (matching path but differing SHA-256) are rewritten to match.
Missing files are recreated.
All file modification times (
mtime) are restored to ensure build tools function deterministically.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelogโฆ
This server cannot be deployed
Maintenance
Related MCP Connectors
Execution platform for AI agents on Firecracker microVMs in the EU. Interactive Linux sandboxes with root, templates for Python, Node.js, Go, Rust and a headless browser, public HTTPS URLs. Background jobs that outlive the connection, batches of up to 1,000 jobs with dependencies, hard cost caps reserved up front, execution receipts with SHA-256, log digests that fit the context. IPv4, dual-stack or IPv6-only with its own public address, allowlists or no network. WASI runtime for small tasks. Idle sandboxes sleep and keep their files. Also REST API, Python SDK and LangChain.
Run AI agent tasks in isolated sandboxes with a cost cap, saved workflows and scoped connections.
Cloud Linux VMs for your agent: run code, Docker, files and HTTPS previews in a Sandboxer microVM.
Run Python code in a secure sandbox without local setup. Declare inline dependencies and execute sโฆ
Related MCP Servers
- AlicenseNot gradedqualityCmaintenanceProvides sandboxed code execution for AI agents with support for Python, JavaScript, and shell commands. Includes comprehensive safety features like destructive pattern blocking, timeout protection, and restricted file access for secure production use.MIT
- AlicenseNot gradedqualityDmaintenanceEnables LLMs to safely execute code in isolated Docker containers with resource limits and security controls, supporting session management and automatic dependency installation.MIT
- AlicenseNot gradedqualityBmaintenanceEnables LLMs to execute Python code securely in a sandboxed environment. Supports configurable restrictions like no network access and returns results including files.1MIT
- AlicenseAqualityCmaintenanceGives an LLM a secure local workspace where it can write files, execute Python in a locked-down Docker container with no network access, and run read-only SQLite queries. Lets the model run, debug, and fix its own code without risking the host machine.6MIT