Safe Local Python Executor/Interpreter
This server provides a secure sandbox environment for executing Python code locally with the following capabilities:
Execute Python scripts for calculations and data manipulations in a restricted environment
Run code securely without requiring Docker or VM setup, working with
uvin a Python virtual environmentEnforce security measures by restricting file I/O operations and limiting imports to a predefined safe list (e.g.,
math,random,datetime)Integrate with LLM applications through a
run_pythontool via Model Context Protocol (MCP) for use in apps like Claude DesktopHandle execution results by requiring output to be stored in a variable named
resultand returning both results and execution logs
Integrates with Hugging Face's LocalPythonExecutor from the smolagents framework to provide secure Python code execution capabilities with basic isolation and security for running LLM-generated Python code.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@Safe Local Python Executor/InterpreterCalculate the factorial of 10 using Python"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
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_pythontoolSafer execution of Python code compared to direct use of Python
eva()lRan 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
Related MCP server: MCP Code Mode
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 claudeInstalling Manually
Install
uv(e.h.brew install uvon macOS or use official docs)Clone the repo, change the directory
cd mcp_safe_local_python_executorThe 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.jsonWindows:
%APPDATA%\Claude\claude_desktop_config.jsonOr open Claude Desktop -> Settings -> Developer -> click "Edit Config" button
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/Available Tools
1 toolrun_pythonA
Execute Python code in a secure sandbox environment.
This tool allows running simple Python code for calculations and data manipulations.
The execution environment is restricted for security purposes. Make sure you create a single file
that can be executed in one go and it returns a result.
Default allowed imports:
- math
- random
- datetime
- time
- json
- re
- string
- collections
- itertools
- functools
- operator
Args:
code: The Python code to execute. Must be valid Python 3 code. The result must be stored in a variable called `result`. E.g.:
```python
import math
result = math.sqrt(16)
```
Returns:
A dictionary with execution results containing:
- result: The final value or None if no value is returned
- logs: Any output from print statements
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes |
Output Schema
| Name | Required | Description |
|---|---|---|
| result | Yes |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations provided, the description carries the full burden of behavioral disclosure. It effectively describes key traits: the secure sandbox environment, restrictions for security, requirement to create a single executable file, and default allowed imports. However, it doesn't cover aspects like execution time limits, memory constraints, or error handling, leaving some behavioral gaps.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is well-structured and front-loaded with the core purpose, followed by usage notes, allowed imports, parameter details, and return information. It's appropriately sized for the tool's complexity, but the list of allowed imports and code example add some length that could be streamlined without losing clarity.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
Given the tool's complexity (code execution with security constraints), no annotations, and an output schema that documents return values, the description is highly complete. It covers purpose, behavioral traits, parameter semantics with examples, and usage context, leaving minimal gaps for an AI agent to understand and invoke the tool correctly.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
The input schema has 0% description coverage, so the description must fully compensate. It adds substantial meaning beyond the schema by detailing the 'code' parameter: it must be valid Python 3 code, require storing results in a variable called 'result', and includes a clear example with syntax and usage. This provides comprehensive semantic context for the single parameter.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description clearly states the tool's purpose: 'Execute Python code in a secure sandbox environment' with specific verbs ('execute', 'run') and resource ('Python code'). It distinguishes the tool's scope by mentioning it's for 'simple Python code for calculations and data manipulations' and operates in a restricted environment, making its function unambiguous even without siblings.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The description implies usage context by specifying it's for 'simple Python code for calculations and data manipulations' and mentions security restrictions, but it lacks explicit guidance on when to use this tool versus alternatives (e.g., other code execution tools or manual methods). No siblings are listed, so differentiation isn't needed, but general usage context is only partially addressed.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections. Dates show when Glama detected each change.
1 tool update
- First observed
run_python
TDQS
With only one tool, there is no possibility of confusion or overlap between tools. The single tool 'run_python' has a clearly defined and distinct purpose.
The naming follows a consistent verb_noun pattern with 'run_python'. Since there's only one tool, consistency is inherently perfect with no deviations to assess.
A single tool is too few for the server's purpose as a 'Safe Local Python Executor/Interpreter'. This suggests a thin surface that may lack essential operations like code validation, environment inspection, or error handling, limiting agent functionality.
The tool set is severely incomplete for the domain. While 'run_python' covers execution, there are obvious gaps such as tools for listing allowed imports, checking code safety, managing execution timeouts, or handling errors, which are critical for a secure interpreter.
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Connectors
Hosted MCP server connecting claude.ai, ChatGPT and other AI apps to your own computer
Security scanner for MCP servers. Detect vulnerabilities, prompt injection, and tool poisoning.
An MCP server that gives your AI access to the source code and docs of all public github repos
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceA MCP server for Hide – headless IDE for coding agents.11MIT
- AlicenseAqualityDmaintenanceUniversal Python code execution MCP server that lets LLMs write and run Python for any task, with auto-install packages, streaming output, and automatic file display.91MIT
- AlicenseNot gradedqualityDmaintenanceAn MCP server that provides secure code execution capabilities using AWS Bedrock AgentCore's CodeInterpreter, supporting Python, JavaScript, TypeScript, shell commands, and file operations.13MIT
- FlicenseNot gradedqualityBmaintenanceA Python MCP server that allows ChatGPT to execute commands on your local PC via a secure Cloudflare tunnel.-
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/maxim-saplin/mcp_safe_local_python_executor'
If you have feedback or need assistance with the MCP directory API, please join our Discord server