MCP AgentRun Server
Provides safe Python code execution capabilities in isolated Docker containers with automatic container lifecycle management using docker-compose
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
MCP AgentRun Server
An MCP (Model Context Protocol) server that provides Python code execution capabilities using AgentRun. This server can execute Python code in isolated Docker containers for safe and reproducible code execution.
Features
Safe Code Execution: Execute Python code in isolated Docker containers
Container Management: Automatic container lifecycle management with docker-compose
Environment Isolation: Each execution runs in a clean, isolated environment
Error Handling: Comprehensive error handling and logging
Easy Integration: Simple MCP interface for AI assistants and tools
Related MCP server: py-sandbox
Installation
Prerequisites
Python 3.13 or higher
Docker and Docker Compose
UV package manager (recommended)
Setup
Clone the repository:
git clone <repository-url>
cd mcp-agentrunRun the setup script:
chmod +x setup.sh
./setup.shUsage
From Cursor
Go to Cursor Settings > Tools and Integrations > [New MCP Server] In the mcp.json file add the following:
{
"mcpServers": {
"python-code-executor": {
"command": "/path/to/mcp-agentrun/.venv/bin/python",
"args": [
"/path/to/mcp-agentrun/src/server.py"
],
"env": {
"PYTHONPATH": "/path/to/mcp-agentrun",
"AGENTRUN_API_DIR": "/path/to/mcp-agentrun/agentrun/agentrun-api",
"PYTHONUNBUFFERED": "1"
}
}
}
}Running the Server
python src/server.pyAvailable Tools
Execute Python Code
Execute Python code in a container:
result = execute_code(
python_code="print('Hello, World!')\nprint(2 + 2)"
)Returns the output of the code execution as a string.
Example Usage
See tests/test_build_container.py for a complete example:
import os
import subprocess
import dotenv
from agentrun import AgentRun
# Setup environment
rootdir = subprocess.run(["git", "rev-parse", "--show-toplevel"],
capture_output=True, text=True).stdout.strip()
agentrun_api_dir = os.path.join(rootdir, "agentrun", "agentrun-api")
dotenv.load_dotenv(os.path.join(agentrun_api_dir, ".env.dev"))
container_name = os.getenv("CONTAINER_NAME")
# Execute code
with ComposeService(agentrun_api_dir):
runner = AgentRun(container_name=container_name)
code_from_llm = "print(1+2)"
result = runner.execute_code_in_container(code_from_llm)
print(result) # Output: 3Project Structure
mcp-agentrun/
├── agentrun/ # AgentRun submodule
├── src/
│ ├── __init__.py
│ └── server.py # MCP server implementation
├── tests/
│ ├── test_build_container.py # Container testing
│ ├── test.py # Unit tests
│ ├── test_integration.py # Integration tests
│ └── dev.ipynb # Development notebook
├── pyproject.toml # Project configuration
├── pytest.ini # Pytest configuration
├── run_tests.py # Test runner script
├── setup.sh # Setup script
└── README.md # This fileConfiguration
The server requires a .env.dev file in the agentrun/agentrun-api/ directory with the following variables:
CONTAINER_NAME=your-container-nameTesting
Dependencies
agentrun>=0.2.5: Python code execution in containersdocker>=7.1.0: Docker API clientfastmcp>=2.10.5: MCP server frameworkpydantic>=2.11.7: Data validationdotenv>=0.9.9: Environment variable managementtenacity>=9.1.2: Retry logic
Development
Adding New Features
Fork the repository
Create a feature branch
Make your changes
Add tests
Submit a pull request
Running in Development Mode
# Install in development mode
uv pip install -e .
# Run the server
python src/server.pyLicense
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Related Projects
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
Related MCP Connectors
Run AI agent tasks in isolated sandboxes with a cost cap, saved workflows and scoped connections.
Scoped agent execution. Server-side credentials, policy, budgets and verifiable receipts.
Execution platform for AI agents on Firecracker microVMs in the EU. Interactive Linux sandboxes with root, templates for Python, Node.js, Go, Rust and a headless browser, public HTTPS URLs. Background jobs that outlive the connection, batches of up to 1,000 jobs with dependencies, hard cost caps reserved up front, execution receipts with SHA-256, log digests that fit the context. IPv4, dual-stack or IPv6-only with its own public address, allowlists or no network. WASI runtime for small tasks. Idle sandboxes sleep and keep their files. Also REST API, Python SDK and LangChain.
Run Python code in a secure sandbox without local setup. Declare inline dependencies and execute s…
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceEnables LLMs to safely execute code in isolated Docker containers with resource limits and security controls, supporting session management and automatic dependency installation.MIT
- AlicenseNot gradedqualityDmaintenanceEnables AI agents to execute arbitrary Python code securely in a sandboxed environment with resource limits and security constraints via MCP protocol.MIT
- FlicenseNot gradedqualityDmaintenanceExecutes Python code in isolated subprocesses with resource limits and timeout, designed for safe execution in Docker containers.-
- FlicenseNot gradedqualityDmaintenanceEnables AI agents to safely execute Python, JavaScript, and Bash code in an isolated Docker sandbox with strict security constraints.1-