Python Sandbox MCP Server

by cloudywu0410

3 stars
438 downloads
Not rated
GitHub

About

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

Details

Author
cloudywu0410
GitHub stars
3
Downloads
438
Categories
Other

- Regular Python code execution with stdout capture
- Matplotlib plotting with PNG image generation

Setting up with Highlight

This MCP is not yet compatible with Highlight’s one-click setup. However, you can still use it with Highlight by following these steps:

  1. Download and install Highlight from highlightai.com/download
  2. Navigate to the plugins tab and select "Add Custom Plugin"
  3. Configure the plugin with the settings below
    Plugin Name Python Sandbox MCP Server
    Command (node, npx, python, etc.)

    Please refer to the README for specific instructions on how to obtain API keys or other required environment variables.

  4. Enable "Start Automatically" if you want the plugin to start when Highlight launches

From the repository

First, clone the repository and install dependencies using uv add -r requirements.txt. Then pull the Snekbox Docker image and start the container with security parameters. Optionally install additional Python packages inside the container. Finally, update your MCP client configuration to point to the local build, e.g., using mcp-proxy with SSE endpoint http://localhost:8060/eval. The server can be configured via environment variables MCP_SERVER_NAME, SNEKBOX_URL, and TEMP_DIR.

Claude Desktop / Cursor

Paste into your MCP client config file to install this server.

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

McpServers

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

Python Sandbox MCP Server

A secure Python code execution server that enables LLMs to run Python code safely in isolated
Docker containers. The server supports:

- Regular Python code execution with stdout capture
- Matplotlib plotting with PNG image generation
- Secure sandboxing via Snekbox Docker container
- Real-time communication using Server-Sent Events (SSE)

Development

To get started with development, follow these steps:

Step 1: Clone the Repository

Fork and clone the repository:

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

Navigate into the project directory:

cd python_sandbox_mcp_server

Step 2: Install Dependencies

Install the required dependencies:

uv add -r requirements.txt

Step 3: Build the Python Sandbox

Pull the Snekbox Container Image:

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

Start the Container with Security Parameters:

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

Install Additional Dependencies (Optional):

- If additional Python packages are required, you can install them as follows:

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 ID of your running Snekbox container and <package_name> with the desired package.

Step 4: Update MCP Server Configuration

Update your MCP server configuration to point to the local build:

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

Configuration

The server can be configured through the following environment variables or by modifying the Config class:

- MCP_SERVER_NAME: Server identifier (default: "python-sandbox-mcp-sse")
- SNEKBOX_URL: Snekbox API endpoint (default: "http://localhost:8060/eval")
- TEMP_DIR: Directory for temporary files storage

License

MIT License

No reviews yet — be the first

Sign in to leave a review

Use Google, GitHub, or an email account so ratings stay tied to real people.

Email sign in

No reviews posted yet.