Safe Local Python Executor
A tool for safely executing local Python code without requiring external data files.
Safe Local Python Executor
An MCP server (stdio transport) that wraps Hugging Face's LocalPythonExecutor
(from the smolagents framework). It is a custom Python runtime that
provides basic isolation/security when running Python code generated by LLMs locally. It does not require Docker or VM.
This package allows to expose the Python executor via MCP (Model Context Protocol) as a tool for LLM apps like Claude Desktop, Cursor or any other MCP compatible client.
In case of Claude Desktop this tool is an easy way to add a missing Code Interpreter (available as a plugin in ChatGPT for quite a while already).
Features
- Exposes
run_pythontool - Safer execution of Python code compared to direct use of Python
eva()l - Ran via uv in Python venv
- No file I/O ops are allowed
- Restricted list of imports
- collections
- datetime
- itertools
- math
- queue
- random
- re
- stat
- statistics
- time
- unicodedata
Security
Be careful with execution of code produced by LLM on your machine, stay away from MCP servers that run Python via command line or using eval(). The safest option is using a VM or a docker container, though it requires some effort to set-up, consumes resources/slower. There're 3rd party servcices providing Python runtime, though they require registration, API keys etc.
LocalPythonExecutor provides a good balance between direct use of local Python environment (which is easier to set-up) AND remote execution in Dokcer container or a VM/3rd party service (which is safe). Hugginng Face team has invested time into creating a quick and safe option to run LLM generated code used by their code agents. This MCP server builds upon it:
To add a first layer of security, code execution in smolagents is not performed by the vanilla Python interpreter. We have re-built a more secure LocalPythonExecutor from the ground up.
Read more here.
Installation and Execution
Installing via Smithery
To install Safe Local Python Executor for Claude Desktop automatically via Smithery:
npx -y @smithery/cli install @maxim-saplin/mcp_safe_local_python_executor --client claude
Installing Manually
- Install
uv(e.h.brew install uvon macOS or use official docs) - Clone the repo, change the directory
cd mcp_safe_local_python_executor - The server can be started via command line
uv run mcp_server.py, venv will be created automatically, depedencies (smollagents, mcp) will be installed
Configuring Claude Desktop
-
Make sure you have Claude for Desktop installed (download from claude.ai)
-
Edit your Claude for Desktop configuration file:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json - Or open Claude Desktop -> Settings -> Developer -> click "Edit Config" button
- macOS:
-
Add the following configuration:
{
"mcpServers": {
"safe-local-python-executor": {
"command": "uv",
"args": [
"--directory",
"/path/to/mcp_local_python_executor/",
"run",
"mcp_server.py"
]
}
}
}
- Restart Claude for Desktop
- The Python executor tool will now be available in Claude (you'll see hammer icon in the message input field)
Example Prompts
Once configured, you can use prompts 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"
Development
Clone the repo. Use uv to create venv, install dev dependencies, run tests:
uv venv .venv
uv sync --group dev
python -m pytest tests/
Related Servers
Scout Monitoring MCP
sponsorPut performance and error data directly in the hands of your AI assistant.
Alpha Vantage MCP Server
sponsorAccess financial market data: realtime & historical stock, ETF, options, forex, crypto, commodities, fundamentals, technical indicators, & more
MCP‑Stack
A Docker Compose-based collection of MCP servers for LLM workflows, featuring centralized configuration and management scripts.
Django MCP Server
A Django extension to enable AI agents to interact with Django apps through the Model Context Protocol.
Mantis MCP Server
An MCP server for integrating with the Mantis Bug Tracker system.
Digma
A code observability MCP enabling dynamic code analysis based on OTEL/APM data to assist in code reviews, issues identification and fix, highlighting risky code etc.
DeepSeek MCP Server
An MCP server for the DeepSeek API, providing code review, file management, and account management.
Instant Meshes MCP
A 3D model processing server for automatic retopology, simplification, and quality analysis of OBJ/GLB models.
OpenFGA
An MCP server for managing authorization models with OpenFGA, an open-source authorization system.
Petclinic
Interacts with the Swagger Petstore API using Petclinic v3 APIs, exposing tools for OpenAI models.
AI Sessions
Searching and access your AI coding sessions from Claude Code, Gemini CLI, opencode, and OpenAI Codex.
MCP Remote Machine Control
Provides remote machine control capabilities, eliminating SSH overhead for token-efficient system operations.
