Code Sandbox MCP server

Provides secure code execution capabilities through containerized sandbox environments, supporting Python and JavaScript with pre-installed libraries for data analysis, visualization, and prototyping without compromising host system security.
Back to servers
Setup instructions
Provider
Philipp Schmid
Release date
Jul 08, 2025
Language
JavaScript
Stats
1 star

The Code Sandbox MCP Server provides a secure environment for AI assistants and LLM applications to execute code snippets using containerized environments. It leverages the llm-sandbox package to safely run code in isolated containers, capturing and returning the execution results.

Installation

You can install the Code Sandbox MCP Server directly from GitHub using pip:

pip install git+https://github.com/philschmid/code-sandbox-mcp.git

Using with an MCP Client

To use the Code Sandbox MCP Server, you need to add it to your Model Context Protocol (MCP) client's configuration. The server is designed to be launched on-demand by the client.

Add the following to your mcpServers configuration:

{
  "mcpServers": {
    "code-sandbox": {
      "command": "code-sandbox-mcp",
    }
  }
}

Available Tools

The Code Sandbox MCP Server provides the following tools:

Run Python Code

Executes Python code in a secure, isolated sandbox:

# Example Python code execution
def hello():
    return "Hello, world!"

print(hello())

Run JavaScript Code

Executes JavaScript (Node.js) code in a secure, isolated sandbox:

// Example JavaScript code execution
function hello() {
    return "Hello, world!";
}

console.log(hello());

Customizing Container Images

The server comes with two pre-built container images:

  • philschmi/code-sandbox-python:latest
  • philschmi/code-sandbox-js:latest

You can build custom images with:

docker build -t philschmi/code-sandbox-python:latest -f containers/Dockerfile.python .
docker build -t philschmi/code-sandbox-js:latest -f containers/Dockerfile.nodejs .

To use your custom images, you can either:

  1. Pass flags when starting the MCP server:

    code-sandbox-mcp --python-image your-image-name --js-image your-js-image
    
  2. Update the image names in the source code constants file

To push custom images to Docker Hub:

docker tag philschmi/code-sandbox-python:latest <your-account>/code-sandbox-python:latest
docker push <your-account>/code-sandbox-python:latest

Testing with MCP Inspector

You can test your server using the MCP inspector:

npx @modelcontextprotocol/inspector

This allows you to inspect and debug the server's behavior when processing code execution requests.

How to install this MCP server

For Claude Code

To add this MCP server to Claude Code, run this command in your terminal:

claude mcp add-json "code-sandbox" '{"command":"code-sandbox-mcp"}'

See the official Claude Code MCP documentation for more details.

For 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 > Tools & Integrations and click "New MCP Server".

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

{
    "mcpServers": {
        "code-sandbox": {
            "command": "code-sandbox-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 explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.

For Claude Desktop

To add this MCP server to Claude Desktop:

1. Find your configuration file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.config/Claude/claude_desktop_config.json

2. Add this to your configuration file:

{
    "mcpServers": {
        "code-sandbox": {
            "command": "code-sandbox-mcp"
        }
    }
}

3. Restart Claude Desktop for the changes to take effect

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