Get the FREE Ultimate OpenClaw Setup Guide →

python_sandbox_mcp_server

A MCP server that enables LLMs to run python code safely in isolated Docker containers.

Installation
Run this command in your terminal to add the MCP server to Claude Code.
Run in terminal:
Command
claude mcp add --transport stdio cloudywu0410-python_sandbox_mcp_server mcp-proxy http://localhost:8060/eval \
  --env TEMP_DIR="Directory for temporary files storage" \
  --env SNEKBOX_URL="Snekbox API endpoint (default: http://localhost:8060/eval)" \
  --env MCP_SERVER_NAME="Server identifier (default: python-sandbox-mcp-sse)"

How to use

This MCP server exposes a secure Python code execution sandbox that your language models can reach via an MCP proxy. It leverages a Snekbox-backed sandbox running inside a Docker container to safely execute Python code, capture stdout, and render plots (e.g., Matplotlib PNGs) as part of the response. The MCP proxy endpoint is configured to forward evaluation requests to the Snekbox service and stream results back to clients using Server-Sent Events (SSE). To use it, point your MCP configuration to the local Snekbox evaluation URL (as shown in the example config) and let your LLM-based tooling send code snippets to be executed in isolation. The system supports standard Python execution and can return visuals generated by plotting libraries, making it suitable for code execution tasks that require output visualization.

How to install

Prerequisites:

  • Docker installed and running
  • Python environment for development (optional if you only deploy via Docker)
  • Git installed

Step 1: Clone the repository

git clone https://github.com/username/python_sandbox_mcp_server.git
cd python_sandbox_mcp_server

Step 2: Install dependencies

uv add -r requirements.txt

Step 3: Build and run the Python sandbox (Snekbox)

Pull the Snekbox container image and run it with security options:

docker pull ghcr.io/python-discord/snekbox:latest

docker run -d --ipc=none --privileged -p 8060:8060 ghcr.io/python-discord/snekbox

Optional: Install additional Python dependencies inside the running Snekbox container

docker exec <container_id> /bin/sh -c \
  'PYTHONUSERBASE=/snekbox/user_base /snekbox/python/default/bin/python -m pip install --user <package_name>'

Replace <container_id> with the actual container ID and <package_name> with the desired package.

Step 4: Update MCP server configuration

Create or modify the MCP configuration to point to the local Snekbox endpoint:

{
  "mcpServers": {
    "python-sandbox-sse": {
      "command": "mcp-proxy",
      "args": [
        "http://localhost:8060/eval"
      ],
      "ssePath": "/eval"
    }
  }
}

Note: The ssePath /eval is where SSE results will be streamed back to the client. If your deployment differs, adjust accordingly.

Additional notes

Tips and common issues:

  • Ensure Docker is running and the Snekbox container is healthy before starting the MCP proxy.
  • If you see connection errors, verify that the Snekbox URL (default http://localhost:8060/eval) is reachable from the MCP server environment.
  • Use the TEMP_DIR setting to store temporary files created during execution to avoid permission issues.
  • The MCP server name (MCP_SERVER_NAME) is optional but helpful for logging and monitoring.
  • When installing additional packages inside the Snekbox container, keep security considerations in mind and only install trusted packages.
  • If you need to adjust the SSL, network, or SSE behavior, consider exposing/ configuring the underlying mcp-proxy and the SSE path accordingly.

Related MCP Servers

Sponsor this space

Reach thousands of developers