home / mcp / safe local python executor mcp server

Safe Local Python Executor MCP Server

Stdio MCP Server wrapping custom Python runtime (LocalPythonExecutor) from Hugging Faces' `smolagents` framework. The runtime combines the ease of setup (compared to docker, VM, cloud runtimes) while providing safeguards and limiting operations/imports that are allowed inside the runtime.

Installation
Add the following to your MCP client configuration file.

Configuration

View docs
{
  "mcpServers": {
    "maxim-saplin-mcp_safe_local_python_executor": {
      "command": "uv",
      "args": [
        "--directory",
        "/path/to/mcp_local_python_executor/",
        "run",
        "mcp_server.py"
      ]
    }
  }
}

You have an MCP server that exposes a safe, local Python execution tool for LLM-driven applications. It wraps a secure Python runtime so you can run Python code generated by LLMs on your machine without Docker or virtual machines, while limiting risky operations and imports.

How to use

After you configure the client, you enable the Python execution tool in your MCP client. Use the hammer icon (or the equivalent tool trigger) in your MCP-compatible app to invoke the Safe Local Python Executor. You can ask the MCP client to run Python snippets or code generated by the LLM, and you’ll receive results from the sandboxed runtime. The tool name exposed is run_python and it runs code inside the restricted environment provided by the executor.

How to install

Prerequisites you need before installation: the uv command line utility and a Node.js environment for MCP tooling.

Installing via Smithery (recommended for Claude Desktop): to auto-install the Safe Local Python Executor for Claude Desktop, run the following command.

npx -y @smithery/cli install @maxim-saplin/mcp_safe_local_python_executor --client claude

Manual installation steps if you prefer to set things up yourself:

# Install uv on your system (example for macOS/Homebrew)
brew install uv

# Clone the project repository
git clone https://example.com/maxim-saplin/mcp_safe_local_python_executor.git
cd mcp_safe_local_python_executor

# Start the server; a Python virtual environment will be prepared automatically
uv run mcp_server.py

Additional configuration for Claude Desktop

To enable the Python execution tool in Claude Desktop, configure Claude to point at the local MCP server using the following setup.

In Claude Desktop, open Developer settings and add this MCP server configuration.

{
  "mcpServers": {
    "safe-local-python-executor": {
      "command": "uv",
      "args": [
        "--directory", 
        "/path/to/mcp_local_python_executor/",
        "run",
        "mcp_server.py"
      ]
    }
  }
}

Example prompts

Once configured, you can prompt the server with requests like:

  • Calculate the factorial of 5 using Python
  • Create a list of prime numbers up to 100
  • Solve this equation (use Python): x^2 + 5x + 6 = 0

Available tools

run_python

Exposes a tool that runs Python code generated by LLMs inside a restricted, local Python runtime with basic isolation and no file I/O.