Safe Local Python Executor/Interpreter
安全なローカル Python エグゼキュータ
Hugging FaceのLocalPythonExecutor ( smolagentsフレームワークより)をラップするMCPサーバー(stdioトランスポート)です。これは、LLMによって生成されたPythonコードをローカルで実行する際に基本的な分離性とセキュリティを提供するカスタムPythonランタイムです。DockerやVMは必要ありません。このパッケージは、Claude Desktop、Cursor、その他のMCP対応クライアントなどのLLMアプリ用のツールとして、MCP(Model Context Protocol)経由でPythonエグゼキューターを公開することを可能にします。Claude Desktopの場合、このツールは不足しているコードインタープリター(ChatGPTのプラグインとして既にかなり以前から利用可能)を簡単に追加する方法です。
特徴
run_pythonツールを公開するPython
eva()lを直接使用するよりも安全に Python コードを実行できますPython venvでuv経由で実行
ファイルI/O操作は許可されません
輸入制限リスト
コレクション
日時
イターツール
数学
列
ランダム
再
統計
統計
時間
ユニコードデータ
Related MCP server: MCP Code Mode
安全
LLM によって生成されたコードを自分のマシンで実行する際は注意してください。コマンドラインやeval()を使って Python を実行する MCP サーバーは使用しないでください。最も安全な選択肢は VM または Docker コンテナを使用することですが、セットアップに多少の手間がかかり、リソースを消費し、速度も低下します。Python ランタイムを提供するサードパーティのサービスもありますが、登録や API キーなどが必要になります。
LocalPythonExecutor 、ローカルPython環境の直接利用(セットアップが容易)と、DokcerコンテナまたはVM/サードパーティサービスでのリモート実行(安全)のバランスに優れています。Hugginng Faceチームは、コードエージェントで使用されるLLM生成コードを迅速かつ安全に実行するためのオプションの開発に時間を費やしました。このMCPサーバーは、このソリューションを基盤としています。
セキュリティの第一層として、smolagents でのコード実行は標準の Python インタープリターでは実行されません。より安全な LocalPythonExecutor をゼロから再構築しました。
詳細はこちらをご覧ください。
インストールと実行
uvをインストールします (macOS ではbrew install uv実行するか、公式ドキュメントを使用してください)リポジトリをクローンし、ディレクトリを変更します
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 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
Inputs: code (required). Returns: result
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
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
Free MCP server for AI agents: Python/JS sandbox, file-to-markdown, speech-to-text.
An MCP server that provides agents access to the KeldynAI platform
Security scanner for MCP servers. Detect vulnerabilities, prompt injection, and tool poisoning.
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.92MIT
- FlicenseNot gradedqualityDmaintenanceA Python MCP server that allows ChatGPT to execute commands on your local PC via a secure Cloudflare tunnel.-
- FlicenseAqualityDmaintenanceA minimal MCP server that lets AI hosts execute shell commands in a sandboxed workspace directory.1-