Enables secure execution of Python code in a sandboxed WebAssembly environment with automatic dependency management, capturing output and return values
Code is executed using Pyodide in Deno and is therefore isolated from the rest of the operating system.
Features
Secure Execution: Run Python code in a sandboxed WebAssembly environment
Package Management: Automatically detects and installs required dependencies
Complete Results: Captures standard output, standard error, and return values
Asynchronous Support: Runs async code properly
Error Handling: Provides detailed error reports for debugging
(This code was previously part of
Usage
To use this server, you must have both Python and Deno installed.
The server can be run with deno installed using uvx:
where:
stdioruns the server with the Stdio MCP transport — suitable for running the process as a subprocess locallystreamable-httpruns the server with the Streamable HTTP MCP transport - suitable for running the server as an HTTP server to connect locally or remotely. This supports stateful requests, but does not require the client to hold a stateful connection like SSEexamplewill run a minimal Python script usingnumpy, useful for checking that the package is working, for the code to run successfully, you'll need to installnumpyusinguvx mcp-run-python --deps numpy example
Usage with Pydantic AI
Then you can use mcp-run-python with Pydantic AI:
Usage in codes as an MCP server
First install the mcp-run-python package:
With mcp-run-python installed, you can also run deno directly with prepare_deno_env or async_prepare_deno_env
Note: prepare_deno_env can take deps as a keyword argument to install dependencies.
As well as returning the args needed to run mcp_run_python, prepare_deno_env creates a new deno environment
and installs the dependencies so they can be used by the server.
Usage in code with code_sandbox
mcp-run-python includes a helper function code_sandbox to allow you to easily run code in a sandbox.
Under the hood, code_sandbox runs an MCP server using stdio. You can run multiple code blocks with a single sandbox.
Logging
MCP Run Python supports emitting stdout and stderr from the python execution as MCP logging messages.
For logs to be emitted you must set the logging level when connecting to the server. By default, the log level is set to the highest level, emergency.
Dependencies
mcp_run_python uses a two step process to install dependencies while avoiding any risk that sandboxed code can
edit the filesystem.
denois first run with write permissions to thenode_modulesdirectory and dependencies are installed, causing wheels to be written to ``denois then run with read-only permissions to thenode_modulesdirectory to run untrusted code.
Dependencies must be provided when initializing the server so they can be installed in the first step.
This server cannot be installed
hybrid server
The server is able to function both locally and remotely, depending on the configuration or use case.
Enables secure execution of Python code in a sandboxed WebAssembly environment using Pyodide and Deno. Automatically handles package management and captures complete execution results including stdout, stderr, and return values.
Related MCP Servers
- -security-license-qualityAn interactive Python code execution environment that allows users and LLMs to safely execute Python code and install packages in isolated Docker containers.Last updated -28Apache 2.0
- -security-license-qualityAn interactive Python code execution tool that allows users and LLMs to safely execute Python code and install packages in isolated Docker containers.Last updated -28Apache 2.0
- Asecurity-licenseAqualityA secure Node.js execution environment that allows coding agents and LLMs to run JavaScript dynamically, install NPM packages, and retrieve results while adhering to the Model Control Protocol.Last updated -7524
- Asecurity-licenseAqualityA Python code execution sandbox based on IPython and Docker. Stateful code execution, file transfer between host and container, configurable network access.Last updated -441Apache 2.0