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
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 claudePart of MCP Servers
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.
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.
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.
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.
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.