{"id":26937577,"url":"https://github.com/maxim-saplin/mcp_safe_local_python_executor","last_synced_at":"2025-05-05T19:36:41.859Z","repository":{"id":284821199,"uuid":"955932781","full_name":"maxim-saplin/mcp_safe_local_python_executor","owner":"maxim-saplin","description":"Stdio MCP Server wrapping custom Python runtime (LocalPythonExecutor) from Hugging Faces' `smolagents` framework. The runtime combines the ease of setup (compared to docker, VM, cloud runtimes) while providing safeguards and limiting operations/imports that are allowed inside the runtime.","archived":false,"fork":false,"pushed_at":"2025-05-01T15:59:57.000Z","size":135,"stargazers_count":15,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-01T16:44:36.231Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/maxim-saplin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-03-27T12:36:20.000Z","updated_at":"2025-05-01T16:00:01.000Z","dependencies_parsed_at":"2025-04-20T04:48:10.027Z","dependency_job_id":null,"html_url":"https://github.com/maxim-saplin/mcp_safe_local_python_executor","commit_stats":null,"previous_names":["maxim-saplin/mcp_safe_local_python_executor"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxim-saplin%2Fmcp_safe_local_python_executor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxim-saplin%2Fmcp_safe_local_python_executor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxim-saplin%2Fmcp_safe_local_python_executor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxim-saplin%2Fmcp_safe_local_python_executor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/maxim-saplin","download_url":"https://codeload.github.com/maxim-saplin/mcp_safe_local_python_executor/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252563304,"owners_count":21768430,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-04-02T13:15:22.480Z","updated_at":"2025-05-05T19:36:41.852Z","avatar_url":"https://github.com/maxim-saplin.png","language":"Python","readme":"# Safe Local Python Executor\n\nAn MCP server (stdio transport) that wraps Hugging Face's [`LocalPythonExecutor`](https://github.com/huggingface/smolagents/blob/main/src/smolagents/local_python_executor.py)\n(from the [`smolagents`](https://huggingface.co/docs/smolagents/en/index) framework). It is a custom Python runtime that \nprovides basic isolation/security when running Python code generated by LLMs locally. It does not require Docker or VM.\nThis 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.\nIn 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).\n\n\u003cimg width=\"1032\" alt=\"image\" src=\"https://github.com/user-attachments/assets/3b820bfc-970a-4315-8f2d-970591c6fdae\" /\u003e\n\n## Features\n\n- Exposes `run_python` tool\n- Safer execution of Python code compared to direct use of Python `eva()l`\n- Ran via uv in Python venv\n- No file I/O ops are allowed\n- Restricted list of imports\n    - collections\n    - datetime\n    - itertools\n    - math\n    - queue\n    - random\n    - re\n    - stat\n    - statistics\n    - time\n    - unicodedata\n\n## Security\n\nBe 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.\n\n`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:\n\n\u003eTo 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.\n\nRead more [here](https://huggingface.co/docs/smolagents/en/tutorials/secure_code_execution#local-code-execution).\n\n## Installation and Execution\n\n1. Install `uv` (e.h. `brew install uv` on macOS or use [official docs](https://docs.astral.sh/uv/getting-started/installation/#__tabbed_1_2))\n2. Clone the repo, change the directory `cd mcp_safe_local_python_executor`\n3. The server can be started via command line `uv run mcp_server.py`, venv will be created automatically, depedencies (smollagents, mcp) will be installed\n\n\n## Configuring Claude Desktop\n\n1. Make sure you have Claude for Desktop installed (download from [claude.ai](https://claude.ai/desktop))\n2. Edit your Claude for Desktop configuration file:\n   - macOS: `~/Library/Application Support/Claude/claude_desktop_config.json`\n   - Windows: `%APPDATA%\\Claude\\claude_desktop_config.json`\n   - Or open Claude Desktop -\u003e Settings -\u003e Developer -\u003e click \"Edit Config\" button\n\n3. Add the following configuration:\n\n```json\n{\n    \"mcpServers\": {\n        \"safe-local-python-executor\": {\n            \"command\": \"uv\",\n            \"args\": [\n                \"--directory\", \n                \"/path/to/mcp_local_python_executor/\",\n                \"run\",\n                \"mcp_server.py\"\n            ]\n        }\n    }\n}\n```\n\n4. Restart Claude for Desktop\n5. The Python executor tool will now be available in Claude (you'll see hammer icon in the message input field)\n\n## Example Prompts\n\nOnce configured, you can use prompts like:\n\n- \"Calculate the factorial of 5 using Python\"\n- \"Create a list of prime numbers up to 100\"\n- \"Solve this equation (use Python): x^2 + 5x + 6 = 0\"\n\n\n## Development\n\nClone the repo. Use `uv` to create venv, install dev dependencies, run tests:\n\n```\nuv venv .venv\nuv sync --group dev\npython -m pytest tests/\n```\n\n-----------------------\n\n\u003ca href=\"https://glama.ai/mcp/servers/@maxim-saplin/mcp_safe_local_python_executor\"\u003e\n  \u003cimg width=\"380\" height=\"200\" src=\"https://glama.ai/mcp/servers/@maxim-saplin/mcp_safe_local_python_executor/badge\" /\u003e\n\u003c/a\u003e\n","funding_links":[],"categories":["CLI Tools","Cloud Infrastructure","MCP 服务器精选列表","サーバー実装","Code Execution","🤖 AI/ML","💻 Operating Systems \u0026 Command Line","Security","Table of Contents","Code Execution \u0026 Automation Mcp Servers"],"sub_categories":["Playwright","🖥️ Command Line","💻 开发与代码执行","🖥️ \u003ca name=\"command-line\"\u003e\u003c/a\u003eコマンドライン","How to Submit","Security"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaxim-saplin%2Fmcp_safe_local_python_executor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaxim-saplin%2Fmcp_safe_local_python_executor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaxim-saplin%2Fmcp_safe_local_python_executor/lists"}