Home / MCP / MCP Run Python Server
Executes Python code in a sandbox with automatic dependencies, capturing outputs and supporting async code.
Configuration
View docs{
"mcpServers": {
"mcp_run_python": {
"command": "uvx",
"args": [
"mcp-run-python",
"stdio"
]
}
}
}MCP Run Python enables you to execute Python code inside a secure, sandboxed environment powered by Pyodide running in Deno. It isolates code from the host system, automatically manages dependencies, and captures outputs for reliable experimentation and automation.
You connect to the MCP Run Python server from an MCP client and choose a transport. The server runs Python code in a sandboxed WebAssembly environment, handling synchronous and asynchronous code, and it reports standard output, standard error, and the return value.
Prerequisites you need on your side are Python and Deno installed on your machine. You then run the MCP server using the provided command, selecting a transport.
Common usage patterns include running the server locally with standard IO transport for subprocess execution, or exposing it as a streamable HTTP endpoint for remote connections. The server supports automatic dependency installation to satisfy your code’s imports.
Key features you can rely on: - Secure execution in a sandboxed WebAssembly environment - Automatic dependency detection and installation - Complete results including stdout, stderr, and return values - Proper handling of asynchronous Python code - Detailed error reports for debugging
Follow these concrete steps to set up MCP Run Python and start using it in your projects.
# Prerequisites: ensure Python and Deno are installed on your system
# Install the MCP Run Python server package (choose one)
pip install mcp-run-python
# or
uv add mcp-run-python
# Run the server locally using the standard IO transport
uvx mcp-run-python stdio
# Alternative transports include streamable-http and streamable-http-stateless
# Example for http transport (if you expose a URL):
# uvx mcp-run-python streamable-http
# Example for stateless http transport (no notifications):
# uvx mcp-run-python streamable-http-stateless
# Optional example to verify dependencies are installed (numpy as a test):
uvx mcp-run-python --deps numpy exampleLogging is supported. To emit logs, set the desired logging level when connecting to the server. By default, the log level starts at the most restrictive level, emergency.
Use the built-in code_sandbox helper to run code blocks in a sandbox without managing long-lived processes. This under the hood creates an MCP server using stdio transport so you can eval multiple blocks in sequence.
from mcp_run_python import code_sandbox
code = """
import numpy
arr = numpy.array([1, 2, 3])
print(arr)
"""
async def main():
async with code_sandbox(dependencies=['numpy']) as sandbox:
result = await sandbox.eval(code)
print(result)
if __name__ == '__main__':
import asyncio
asyncio.run(main())Code runs inside a sandbox environment with isolated access to system resources. Dependencies are detected and installed as needed, ensuring the sandbox remains protected from host filesystem modifications.
Helper to run code blocks in a sandboxed MCP server, enabling multiple evaluations without restarting the server.
Prepare a Deno environment with dependencies for running the MCP server.
Asynchronously prepare a Deno environment for running the MCP server and retrieve run arguments.
Utility to prepare the argument set required to launch the MCP server under Deno.