Skip to main content

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).

image

Features

  • Exposes run_python tool
  • 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

  1. Install uv (e.h. brew install uv on macOS or use official docs)
  2. Clone the repo, change the directory cd mcp_safe_local_python_executor
  3. 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

  1. Make sure you have Claude for Desktop installed (download from claude.ai)

  2. 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
  3. Add the following configuration:

{
    "mcpServers": {
        "safe-local-python-executor": {
            "command": "uv",
            "args": [
                "--directory", 
                "/path/to/mcp_local_python_executor/",
                "run",
                "mcp_server.py"
            ]
        }
    }
}
  1. Restart Claude for Desktop
  2. 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/

smithery badge

MseeP.ai Security Assessment Badge

Metadata

Release files for iflow-mcp_maxim-saplin-mcp_safe_local_python_executor 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for iflow-mcp_maxim-saplin-mcp_safe_local_python_executor 0.1.0
File Size Uploaded
iflow_mcp_maxim_saplin_mcp_safe_local_python_executor-0.1.0.tar.gz 6.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for iflow-mcp_maxim-saplin-mcp_safe_local_python_executor 0.1.0
File Interpreter ABI Platform
iflow_mcp_maxim_saplin_mcp_safe_local_python_executor-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 12.7 kB

Release files / iflow_mcp_maxim_saplin_mcp_safe_local_python_executor-0.1.0.tar.gz

Download URL iflow_mcp_maxim_saplin_mcp_safe_local_python_executor-0.1.0.tar.gz
Size 6.4 kB
Tags Source
SHA-256 checksum
How to use checksums
8fd70644862bcd14208a98fc10f3868cc868cc053d88b1802b5056f64b01a7a2
BLAKE2b-256 checksum
How to use checksums
0a7110dddfe2ed6adf2fc29c0b38af3e52e488acc8287b990e705a188527b842
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.10.0 {"installer":{"name":"uv","version":"0.10.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / iflow_mcp_maxim_saplin_mcp_safe_local_python_executor-0.1.0-py3-none-any.whl

Download URL iflow_mcp_maxim_saplin_mcp_safe_local_python_executor-0.1.0-py3-none-any.whl
Size 6.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9e0ea8a4bac6f45012c61c51646f323cbb2530bdb0217dd585b29efb8487160a
BLAKE2b-256 checksum
How to use checksums
0df3a44d4fa9ecfbd2ef19b340e3888a1279e1a56c964a71b034317284bc9b79
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.10.0 {"installer":{"name":"uv","version":"0.10.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page