Home / MCP / Code Sandbox MCP Server

Code Sandbox MCP Server

Lightweight, STDIO-based MCP server that runs Python or JavaScript code in containerized sandboxes and returns outputs.

python
Installation
Add the following to your MCP client configuration file.

Configuration

View docs
{
    "mcpServers": {
        "code_sandbox": {
            "command": "code-sandbox-mcp",
            "args": [],
            "env": {
                "API_KEY": "1234567890",
                "SECRET_TOKEN": "abcdef1234",
                "CONTAINER_IMAGE": "your-own-image",
                "CONTAINER_LANGUAGE": "python"
            }
        }
    }
}

The Code Sandbox MCP Server enables safe, containerized execution of code snippets via a lightweight STDIO-based MCP server. It integrates with your MCP client to run Python or JavaScript code in isolated containers and return outputs and errors for prompt feedback.

How to use

You use the Code Sandbox MCP Server by connecting your MCP client to the local server process. Start the MCP server as part of your application startup, then send code snippets to be executed in a secure sandbox. The server runs the code inside a container, captures standard output and errors, and returns them to you for display or further processing. You can run Python or JavaScript code snippets, and you can opt to pass through environment variables to influence the sandboxed environment.

How to install

Prerequisites: you need Python with pip installed to install the MCP server package. You also need Docker or Podman installed if you plan to run container-backed sandboxes.

# Install the MCP server package
pip install git+https://github.com/philschmid/code-sandbox-mcp.git

# Optional: verify Python and pip versions
python --version
pip --version

Configure and run the server

You connect to the server by configuring your MCP client to use the stdio MCP endpoint provided by the code-sandbox-mcp package. The following configuration example shows how to declare the MCP server in your client settings.

{
  "mcpServers": {
    "code_sandbox": {
      "command": "code-sandbox-mcp",
      "args": [],
      "env": {
        // optional environment variables you expose to the sandbox
      }
    }
  }
}

Passing through environment variables

If you want to pass through sensitive values to the sandbox, provide them as environment variables when starting the MCP server and reference them in your client configuration.

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

Customize or use a custom container image

You can provide a custom container image and language by setting environment variables when starting the MCP server. The container image and language are used to determine the code execution environment.

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

Available tools

run_python_code

Executes a Python snippet inside a secure, isolated sandbox. Provide the Python code as the code argument.

run_js_code

Executes a JavaScript (Node.js) snippet inside a secure, isolated sandbox. Provide the JavaScript code as the code argument.