Safe Local Python Executor logo

Safe Local Python Executor

by maxim-saplin

This MCP server wraps Hugging Face's LocalPythonExecutor to provide a safer way to execute Python code generated by LLMs locally without Docker or VMs. It exposes the Python executor via MCP, enabling its use as a tool for LLM applications like Claude Desktop and Cursor.

View on GitHub

Last updated: N/A

What is Safe Local Python Executor?

The Safe Local Python Executor is an MCP server that provides a secure environment for running Python code generated by Large Language Models (LLMs). It leverages Hugging Face's LocalPythonExecutor to offer basic isolation and security without the overhead of Docker or virtual machines.

How to use Safe Local Python Executor?

  1. Install uv. 2. Clone the repository. 3. Start the server using uv run mcp_server.py. 4. Configure your MCP-compatible client (e.g., Claude Desktop) by adding the server configuration to its settings file, specifying the command and arguments to run the server. 5. Restart the client. The Python executor tool will then be available.

Key features of Safe Local Python Executor

  • Exposes run_python tool via MCP

  • Safer execution of Python code compared to eval()

  • Runs in a Python venv using uv

  • Restricted file I/O

  • Limited list of allowed imports for enhanced security

Use cases of Safe Local Python Executor

  • Adding a Code Interpreter to Claude Desktop

  • Executing Python code generated by LLMs in a controlled environment

  • Providing a secure Python runtime for LLM-powered applications

  • Integrating Python execution capabilities into MCP-compatible clients

FAQ from Safe Local Python Executor

What is MCP?

MCP stands for Model Context Protocol. It's a protocol that allows LLM applications to interact with external tools and services.

Why use this instead of just running Python code directly?

Directly running LLM-generated code can be risky. This executor provides a safer environment with restrictions on file I/O and allowed imports.

Is this as secure as using Docker or a VM?

No, using a VM or Docker container is generally more secure. However, this executor offers a good balance between security and ease of setup/resource consumption.

What are the allowed imports?

The allowed imports are: collections, datetime, itertools, math, queue, random, re, stat, statistics, time, and unicodedata.

How do I configure this for Claude Desktop?

You need to edit the Claude Desktop configuration file (claude_desktop_config.json) and add the MCP server configuration, specifying the path to the mcp_server.py file and the uv run command.