Code Sandbox MCP server

Provides secure, isolated Python code execution environments with modular architecture for running untrusted code, testing solutions, generating visualizations, and performing file operations through multiple backend options including E2B and Firecracker microVMs.
Back to servers
Provider
Chris Hay
Release date
Mar 12, 2025
Language
Python
Stats
10 stars

This MCP Code Sandbox Server provides secure code execution capabilities in isolated sandbox environments, following the Message Communication Protocol (MCP) standard. It's compatible with Claude for Desktop and other MCP clients, allowing you to execute Python code, manage files, and install packages in a secure environment.

Installation

Prerequisites

  • Python 3.10 or higher
  • E2B API key (for the default E2B interpreter)

Setup Steps

  1. Clone the repository:

    git clone https://github.com/yourusername/mcp-code-sandbox.git
    cd mcp-code-sandbox
    
  2. Set up a virtual environment:

    # Using venv
    python -m venv venv
    source venv/bin/activate  # On Windows: venv\Scripts\activate
    
    # Or using uv (recommended)
    uv init
    uv venv
    source .venv/bin/activate  # On Windows: .venv\Scripts\activate
    
  3. Install required packages:

    # Using pip
    pip install fastmcp python-dotenv e2b-code-interpreter
    
    # Or using uv
    uv add fastmcp python-dotenv e2b-code-interpreter
    
  4. Configure environment variables by creating a .env file:

    E2B_API_KEY=your_e2b_api_key_here
    INTERPRETER_TYPE=e2b  # Default, can be changed to other implemented interpreters
    

Usage

Running the Server Standalone

Start the server directly from the command line:

python main.py

This launches the server using stdio transport, making it compatible with Claude for Desktop.

Integration with Claude for Desktop

  1. Ensure you have the latest version of Claude for Desktop

  2. Open your Claude for Desktop configuration file:

    • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
    • Windows: %APPDATA%\Claude\claude_desktop_config.json
  3. Add your code sandbox server configuration:

    {
      "mcpServers": {
        "code-sandbox": {
          "command": "python",
          "args": [
            "/ABSOLUTE/PATH/TO/main.py"
          ]
        }
      }
    }
    

    Or if using uv:

    {
      "mcpServers": {
        "code-sandbox": {
          "command": "uv",
          "args": [
            "--directory",
            "/ABSOLUTE/PATH/TO/PROJECT_DIRECTORY",
            "run",
            "main.py"
          ]
        }
      }
    }
    
  4. Save the file and restart Claude for Desktop

Available Tools

Sandbox Administration

  • create_sandbox: Create a new sandbox environment
  • close_sandbox: Close and clean up a sandbox
  • get_sandbox_status: Check status of sandboxes

Code Execution

  • execute_code: Run Python code in a sandbox
  • install_package: Install a Python package
  • create_run_close: All-in-one tool that creates a sandbox, runs code, and cleans up

File Operations

  • list_files: List files in the sandbox
  • read_file: Read the contents of a file
  • write_file: Write content to a file
  • upload_file: Upload a file to the sandbox

Troubleshooting

If you encounter issues:

  • Verify your API key for the chosen interpreter is correct
  • Check logs for detailed error messages
  • Ensure all required packages are installed
  • Confirm Claude for Desktop is configured with the correct path to your script

How to add this MCP server to Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > MCP and click "Add new global MCP server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "cursor-rules-mcp": {
            "command": "npx",
            "args": [
                "-y",
                "cursor-rules-mcp"
            ]
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later