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
177 stars

The Code Sandbox MCP Server is a lightweight tool that allows AI assistants and LLM applications to safely execute code snippets in containerized environments. It provides a secure way to run Python and JavaScript code through the Model Context Protocol (MCP).

Installation

You can install the Code Sandbox MCP Server using pip:

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

Basic Usage

The server provides two main tools:

  • run_python_code: Executes Python code in an isolated sandbox
  • run_js_code: Executes JavaScript (Node.js) code in an isolated sandbox

Configuring with an MCP Client

To use the Code Sandbox MCP server, add it to your MCP client's configuration file:

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

Advanced Configuration

Passing Environment Variables

You can securely pass environment variables to the sandbox:

{
  "mcpServers": {
    "code-sandbox": {
      "command": "code-sandbox-mcp",
      "args": ["--pass-through-env", "API_KEY,SECRET_TOKEN"],
      "env": {
        "API_KEY": "1234567890",
        "SECRET_TOKEN": "1234567890"
      }
    }
  }
}

Using a Custom Container Image

You can specify a custom container image:

{
  "mcpServers": {
    "code-sandbox": {
      "command": "code-sandbox-mcp",
      "env": {
        "CONTAINER_IMAGE": "your-own-image",
        "CONTAINER_LANGUAGE": "python"
      }
    }
  }
}

Integration with Gemini

Using with Gemini SDK

Here's how to use the server with the Gemini SDK:

from fastmcp import Client
from google import genai
import asyncio

mcp_client = Client(
    {
        "local_server": {
            "transport": "stdio",
            "command": "code-sandbox-mcp",
        }
    }
)
gemini_client = genai.Client()

async def main():
    async with mcp_client:
        response = await gemini_client.aio.models.generate_content(
            model="gemini-2.5-flash",
            contents="Use Python to ping the google.com website and return the response time.",
            config=genai.types.GenerateContentConfig(
                temperature=0,
                tools=[mcp_client.session],  # Pass the FastMCP client session
            ),
        )
        print(response.text)

if __name__ == "__main__":
    asyncio.run(main())

Using with Gemini CLI

Add the MCP server configuration to your Gemini CLI settings:

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

You can add this either to your global settings at ~/.gemini/settings.json or to your project's .gemini/settings.json file.

Testing

Using MCP Inspector

You can test your server using the MCP inspector:

npx @modelcontextprotocol/inspector

Running Tests

To run the test suite:

# Install development dependencies
pip install -e ".[dev]"

# Run the tests
pytest tests/

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