安全Python执行器
STDIO用于安全执行Python代码的MCP服务器
用于安全执行Python代码的MCP服务器
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).
run_python
tooleva()l
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.
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
uv
(e.h. brew install uv
on macOS or use official docs)cd mcp_safe_local_python_executor
uv run mcp_server.py
, venv will be created automatically, depedencies (smollagents, mcp) will be installedMake sure you have Claude for Desktop installed (download from claude.ai)
Edit your Claude for Desktop configuration file:
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%\Claude\claude_desktop_config.json
Add the following configuration:
{ "mcpServers": { "safe-local-python-executor": { "command": "uv", "args": [ "--directory", "/path/to/mcp_local_python_executor/", "run", "mcp_server.py" ] } } }
Once configured, you can use prompts like:
Clone the repo. Use uv
to create venv, install dev dependencies, run tests:
uv venv .venv
uv sync --group dev
python -m pytest tests/