Safe Local Python Executor

Safe Local Python Executor is an MCP server that enables AI clients to execute Python code locally within a secure, sandboxed runtime. Built on the LocalPythonExecutor from Hugging Face's smolagents library, it provides developers and AI assistant users with a lightweight code interpreter that does not require virtual machines or Docker containers. The server connects Model Context Protocol clients like Claude Desktop and Cursor to a restricted Python environment via standard input and output. Developers, researchers, and data analysts use it to compute mathematical formulas, manipulate text, run statistical algorithms, and generate data sequences without leaving their chat workspace. By eliminating direct calls to the operating system shell or vanilla evaluation functions, it blocks file input/output operations and restricts module imports strictly to standard libraries such as math, statistics, datetime, and collections. This architecture prevents generated code from reading host disk storage, accessing local networks, or altering system files. The server acts as a drop-in execution layer for LLM-driven computational tasks, returning console output and calculated variables directly back to the client interface.

Category: Cloud & Infrastructure

Tags: code-execution, python, sandbox, security

Visit Safe Local Python Executor

How to install and configure Safe Local Python Executor

  1. Install uv using your package manager (such as brew install uv on macOS) or following the official astral documentation. 2. Clone the repository and enter the directory: bash git clone https://github.com/maxim-saplin/mcp_safe_local_python_executor cd mcp_safe_local_python_executor 3. Open your Claude Desktop configuration file (claude_desktop_config.json) located in ~/Library/Application Support/Claude/ on macOS or %APPDATA%\Claude\ on Windows. 4. Add the server under mcpServers: json { "mcpServers": { "safe-local-python-executor": { "command": "uv", "args": [ "--directory", "/path/to/mcp_local_python_executor/", "run", "mcp_server.py" ] } } } 5. Replace /path/to/mcp_local_python_executor/ with your local path and restart Claude for Desktop. Alternatively, install automatically using Smithery: bash npx -y @smithery/cli install @maxim-saplin/mcp_safe_local_python_executor --client claude

What you can do with Safe Local Python Executor

  • Calculate factorials, permutations, or complex mathematical equations directly within Claude conversations without relying on LLM arithmetic hallucinations. - Generate sequences of prime numbers, Fibonacci series, or random mock datasets using standard Python modules like math, random, and itertools. - Parse, validate, and transform structured string data using regular expressions and unicode utilities without permitting unsafe system calls. - Run statistical calculations on user-provided number arrays using the standard statistics library to obtain means, medians, variances, and standard deviations. - Process and format timestamps, dates, and intervals using the datetime and time modules for scheduling and timeline calculations.

Key facts

  • https://github.com/maxim-saplin/mcp_safe_local_python_executor
  • Cloud & Infrastructure, Developer Tools & Code Intelligence
  • code-execution, python, sandbox, security

Part of MCP Servers

Related MCP servers

  • MCP KQL Server — MCP KQL Server is an MCP server that connects AI assistants to Azure Data Explorer clusters using Azure CLI authentication.…
  • MCP LaTeX Server — MCP LaTeX Server is an MCP server that provides tools for creating, editing, validating, and compiling LaTeX documents directly through…
  • MCP JSON — MCP JSON is an MCP server collection that bundles tools for file system operations, Google search, browser-based web automation, and…
  • MCP Jupyter Complete — MCP Jupyter Complete is an MCP server that provides tools for manipulating Jupyter notebook files through position-based cell operations and…
  • MCP LSP Go — MCP LSP Go is an MCP server that connects AI assistants to the official Go Language Server Protocol implementation, gopls,…
  • MCP Manager — MCP Manager is an MCP server management tool that connects directly to your Claude Desktop environment, enabling users to discover,…

What is Safe Local Python Executor?

Safe Local Python Executor is a Model Context Protocol server that wraps Hugging Face smolagents LocalPythonExecutor. It lets AI assistants like Claude Desktop execute Python code locally inside a restricted runtime environment, providing an isolated code interpreter without the operational overhead of managing Docker containers or virtual machines.

What Python libraries can be imported?

Execution is restricted to an allowlist of standard Python modules. Allowed libraries include collections, datetime, itertools, math, queue, random, re, stat, statistics, time, and unicodedata. Other imports, as well as file input and output operations, are blocked to maintain execution safety on the host machine.

Which MCP clients work with Safe Local Python Executor?

Any client supporting the Model Context Protocol standard over stdio transport can connect to Safe Local Python Executor. Verified clients include Claude Desktop and Cursor. Users configure the server by pointing their client configuration file to the uv executable running the mcp_server.py script.

How does it isolate code execution without Docker?

Instead of passing code directly to the standard Python interpreter or eval function, this server uses the custom LocalPythonExecutor runtime created by Hugging Face. The runtime parses and restricts the abstract syntax tree, rejecting forbidden operations like file system access and disallowing unauthorized module imports.

How do I test the server after installation?

Once configured in Claude Desktop, a hammer icon will appear in the message input area indicating tool availability. You can verify functionality by prompting the assistant to calculate a factorial, solve an algebraic equation, or generate prime numbers using the run_python tool.

  • AI Tools
  • Categories
  • Industries
  • CLI Coding Agents
  • MCP Servers
  • MCP Categories