Safe Local Python Executor/Interpreter
安全的本地 Python 执行器
一个 MCP 服务器(stdio 传输),它封装了 Hugging Face 的LocalPythonExecutor (来自smolagents框架)。它是一个自定义的 Python 运行时,在本地运行 LLM 生成的 Python 代码时提供基本的隔离/安全性。它不需要 Docker 或虚拟机。此包允许通过 MCP(模型上下文协议)将 Python 执行器公开为 LLM 应用(例如 Claude Desktop、Cursor 或任何其他兼容 MCP 的客户端)的工具。对于 Claude Desktop,此工具可以轻松添加缺少的代码解释器(ChatGPT 中已作为插件提供一段时间了)。
特征
公开
run_python工具与直接使用 Python
eva()l相比,Python 代码的执行更安全通过 Python venv 中的 uv 运行
不允许文件 I/O 操作
限制进口商品清单
收藏品
日期时间
迭代工具
数学
队列
随机的
关于
统计
统计数据
时间
unicode数据
Related MCP server: MCP Code Mode
安全
在你的机器上执行 LLM 生成的代码时要小心,远离通过命令行或使用eval()运行 Python 的 MCP 服务器。最安全的选择是使用虚拟机或 Docker 容器,尽管这需要一些设置工作,消耗资源/速度较慢。有一些第三方服务提供 Python 运行时,但它们需要注册、API 密钥等。
LocalPythonExecutor在直接使用本地 Python 环境(更易于设置)和在 Dokcer 容器或虚拟机/第三方服务中远程执行(更安全)之间提供了良好的平衡。Hugginng Face 团队投入了大量时间,创建了一个快速安全的选项,用于运行其代码代理使用的 LLM 生成的代码。此 MCP 服务器以此为基础构建:
为了增加第一层安全性,smolagents 中的代码执行并非由原生 Python 解释器执行。我们从头开始重新构建了一个更安全的 LocalPythonExecutor。
点击此处了解更多信息。
安装和执行
安装
uv(在 macOS 上brew install uv或者使用官方文档)克隆 repo,更改目录
cd mcp_safe_local_python_executor可以通过命令行
uv run mcp_server.py启动服务器,venv 将自动创建,依赖项(smollagents、mcp)将被安装
配置 Claude 桌面
确保已安装 Claude for Desktop(从claude.ai下载)
编辑 Claude for Desktop 配置文件:
macOS:
~/Library/Application Support/Claude/claude_desktop_config.jsonWindows:
%APPDATA%\Claude\claude_desktop_config.json或者打开 Claude Desktop -> 设置 -> 开发者 -> 点击“编辑配置”按钮
添加以下配置:
{
"mcpServers": {
"safe-local-python-executor": {
"command": "uv",
"args": [
"--directory",
"/path/to/mcp_local_python_executor/",
"run",
"mcp_server.py"
]
}
}
}重启 Claude 桌面版
Python 执行器工具现在将在 Claude 中可用(您将在消息输入字段中看到锤子图标)
示例提示
配置完成后,您可以使用如下提示:
“使用 Python 计算 5 的阶乘”
“创建一个 100 以内的素数列表”
“解这个方程(使用 Python):x^2 + 5x + 6 = 0”
发展
克隆仓库。使用uv创建 venv,安装开发依赖项,运行测试:
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.
1 tool update
- First observed
run_python
TDQS
Scored across 1 tool
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
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
- FlicenseNot gradedqualityBmaintenanceA Python MCP server that allows ChatGPT to execute commands on your local PC via a secure Cloudflare tunnel.-
- FlicenseAqualityCmaintenanceA minimal MCP server that lets AI hosts execute shell commands in a sandboxed workspace directory.1-