maxim-saplin/mcp_safe_local_python_executor logo

maxim-saplin/mcp_safe_local_python_executor

Free

Safe Python interpreter based on HF Smolagents `LocalPythonExecutor`

FreeFree tier
Type
Open Source

About maxim-saplin/mcp_safe_local_python_executor

A Model Context Protocol (MCP) server that wraps Hugging Face's LocalPythonExecutor from the smolagents framework to provide a safer local Python execution environment for LLM-generated code. It runs via uv in a Python virtual environment, restricts file I/O operations, and limits allowed imports to a curated set (collections, datetime, itertools, math, queue, random, re, stat, statistics, time, unicodedata). The server exposes a run_python tool that can be used with MCP clients such as Claude Desktop, Cursor, or any other compatible application. It balances ease of setup (no Docker or VM required) with basic security, making it a quick local alternative to remote code interpreter services while still requiring caution when executing LLM-produced code.

Key Features

Exposes `run_python` tool via MCP (stdio transport)
Safer execution compared to direct use of Python `eval()`
Runs via `uv` in a Python virtual environment (no Docker/VM needed)
No file I/O operations allowed
Restricted list of allowed imports: collections, datetime, itertools, math, queue, random, re, stat, statistics, time, unicodedata
Leverages Hugging Face's `LocalPythonExecutor` for enhanced security over vanilla Python
Compatible with Claude Desktop, Cursor, and any MCP client

Pros & Cons

Pros
  • Quick and easy setup: no Docker, VM, or cloud registration required
  • Provides basic isolation and security compared to using `eval()` or command-line execution
  • Free and open-source (MIT license)
  • Uses proven safeguards from Hugging Face's smolagents framework
  • Works with popular MCP clients like Claude Desktop and Cursor
Cons
  • Not as secure as running code in a Docker container or VM (still runs on the local machine)
  • Limited to a restricted set of imports; many standard library modules unavailable
  • No file I/O allowed, limiting certain use cases (e.g., reading/writing files)
  • Still requires trust in the LLM output—user must be cautious about what code is executed

Best For

Enabling code interpreter functionality in Claude Desktop (similar to ChatGPT Code Interpreter)Safe execution of Python code generated by LLM agents or chatbotsLocal alternative to remote code execution services (e.g., Docker, VM, third-party APIs)Prototyping and testing AI-generated code in a controlled environment

FAQ

How does this compare to running code in Docker or a VM?
This tool is easier to set up (no Docker/VM required) but provides less isolation. The official recommendation advises using a VM or Docker for maximum security; this server is a compromise for convenience.
What Python imports are allowed?
The allowed imports are: collections, datetime, itertools, math, queue, random, re, stat, statistics, time, and unicodedata. All other imports are blocked.
Can I install this server via Smithery?
Yes, you can install it for Claude Desktop automatically using Smithery: `npx -y @smithery/cli install @maxim-saplin/mcp_safe_local_python_executor --client claude`.