Code Sandbox MCP server

Provides secure code execution across 7 programming languages through Docker containerization with real-time output streaming, syntax validation, and comprehensive security controls including network isolation and resource limits.
Back to servers
Setup instructions
Provider
timlikesai
Release date
Jul 13, 2025
Language
JavaScript
Stats
2 stars

The Code Sandbox MCP Server is a secure Docker-based solution for executing code in multiple languages that implements the Model Context Protocol. It runs in isolated containers with resource limits and supports 12 programming languages including Python, JavaScript, Ruby, and various JVM languages.

Installation Options

Using Pre-built Images

# Pull the latest image from GitHub Container Registry
docker pull ghcr.io/timlikesai/code-sandbox-mcp:latest

# Run directly
docker run --rm --interactive ghcr.io/timlikesai/code-sandbox-mcp:latest

Building from Source

# Build the Docker image
docker compose build

# Run tests (optional)
docker compose run --rm code-sandbox bundle exec rspec

Configuration

Basic Configuration

Add this configuration to Claude Desktop settings file or Claude Code's .mcp.json file:

{
  "mcpServers": {
    "code-sandbox": {
      "command": "docker",
      "args": [
        "run", "--rm", "--interactive",
        "--network", "none",
        "ghcr.io/timlikesai/code-sandbox-mcp:latest"
      ]
    }
  }
}

For Claude Code CLI, you can add via command line:

claude mcp add code-sandbox -- docker run --rm --interactive --network none ghcr.io/timlikesai/code-sandbox-mcp:latest

Advanced Security Configuration

For additional security hardening:

{
  "mcpServers": {
    "code-sandbox": {
      "command": "docker",
      "args": [
        "run", "--rm", "--interactive",
        "--read-only",
        "--tmpfs", "/tmp",
        "--tmpfs", "/app/tmp",
        "--memory", "512m",
        "--cpus", "0.5",
        "--network", "none",
        "--security-opt", "no-new-privileges",
        "--cap-drop", "ALL",
        "ghcr.io/timlikesai/code-sandbox-mcp:latest"
      ]
    }
  }
}

Network Access Configuration

The container supports networking, but it's recommended to use Docker's --network none flag to disable it for security. To enable network access when needed, remove this flag:

{
  "mcpServers": {
    "code-sandbox": {
      "command": "docker",
      "args": [
        "run", "--rm", "--interactive",
        "--network", "none",
        "ghcr.io/timlikesai/code-sandbox-mcp:latest"
      ]
    },
    "code-sandbox-network": {
      "command": "docker",
      "args": [
        "run", "--rm", "--interactive",
        "ghcr.io/timlikesai/code-sandbox-mcp:latest"
      ]
    }
  }
}

Network access is required for API calls, package installation, web scraping, and external service integration.

Usage

Available Tools

The MCP server provides three main tools:

  1. execute_code - Execute code with automatic session management
  2. validate_code - Validate syntax without execution
  3. reset_session - Reset sessions for specific languages or all languages

Session Management

Code execution is stateful by default. Each language maintains its own isolated session with variables, function/class definitions, imported modules, and execution history. Sessions expire after 1 hour of inactivity.

Quick Testing

# Test execution (with network disabled)
echo '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"execute_code","arguments":{"language":"python","code":"print(\"Hello World!\")"}}}' | docker run --rm -i --network none ghcr.io/timlikesai/code-sandbox-mcp:latest

# Test with network access and package installation
echo '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"execute_code","arguments":{"language":"python","code":"import subprocess; subprocess.run([\"pip\", \"install\", \"requests\"]); import requests; print(requests.get(\"https://httpbin.org/ip\").json())"}}}' | docker run --rm -i ghcr.io/timlikesai/code-sandbox-mcp:latest

# Debug mode
docker run --rm -it --network none ghcr.io/timlikesai/code-sandbox-mcp:latest bash

Security Features

The server implements multiple layers of container security:

  • Container isolation with resource limits (512MB memory, 0.5 CPU)
  • Ephemeral filesystem - nothing persists after container stops
  • Package installation safety - packages install in container temp space only
  • Network isolation (configurable via Docker's --network none flag)
  • Read-only root filesystem with writable /tmp only
  • No privileges (--security-opt no-new-privileges, --cap-drop ALL)
  • Non-root user (executes as sandbox user)
  • Auto-cleanup (--rm removes containers after execution)
  • Configurable timeout (default 30s via EXECUTION_TIMEOUT)

When network access is enabled, users can install packages safely within the container. All installations are ephemeral and don't affect the host system or persist between container restarts.

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":"docker","args":["run","--rm","--interactive","--network","none","ghcr.io/timlikesai/code-sandbox-mcp:latest"]}'

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": "docker",
            "args": [
                "run",
                "--rm",
                "--interactive",
                "--network",
                "none",
                "ghcr.io/timlikesai/code-sandbox-mcp:latest"
            ]
        }
    }
}

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": "docker",
            "args": [
                "run",
                "--rm",
                "--interactive",
                "--network",
                "none",
                "ghcr.io/timlikesai/code-sandbox-mcp:latest"
            ]
        }
    }
}

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