Skip to main content

Code Execution MCP Server

A Model Context Protocol (MCP) server that exposes Agent Zero's battle-tested code execution capabilities.

This MCP server allows any AI agent (Claude, Cursor, Windsurf, etc.) to execute terminal commands and Python code on the host system using Agent Zero's proven implementation.

Features

  • Execute Terminal Commands: Run shell commands with full session persistence
  • Execute Python Code: Run Python code via IPython with session management
  • Multiple Sessions: Maintain separate execution contexts
  • Smart Output Handling: Automatic prompt detection, timeout management, and dialog detection
  • Cross-Platform: Works on Linux, macOS, and Windows (experimental)

MCP Client Configuration (no installation needed)

Add to your application MCP config:

  • simple case using uvx
{
  "mcpServers": {
    "code-execution": {
      "command": "uvx",
      "args": ["code-execution-mcp"]
    }
  }
}
  • or pipx if uvx is not installed
{
  "mcpServers": {
    "code-execution": {
      "command": "pipx",
      "args": ["run", "code-execution-mcp"]
    }
  }
}

Additional configuration

The MCP server can be configured via environment variables:

# Shell executable (default: /bin/bash on Unix, powershell.exe on Windows)
export CODE_EXEC_EXECUTABLE=/bin/bash

# Init commands (semicolon-separated, run when creating new sessions, empty by default)
export CODE_EXEC_INIT_COMMANDS="source /path/to/venv/bin/activate;export PATH=\$PATH:/custom/bin"

# Timeout configuration (in seconds)
export CODE_EXEC_FIRST_OUTPUT_TIMEOUT=30      # Wait for first output
export CODE_EXEC_BETWEEN_OUTPUT_TIMEOUT=15    # Wait between output chunks
export CODE_EXEC_DIALOG_TIMEOUT=5             # Detect dialog prompts
export CODE_EXEC_MAX_EXEC_TIMEOUT=180         # Maximum execution time

# Log directory (default empty = logging disabled)
export CODE_EXEC_LOG_DIR=/path/to/logs

Additional examples

  • start sessions with custom shell and python environment + logging
{
  "mcpServers": {
    "code-execution-mcp": {
      "command": "uvx",
      "args": ["code-execution-mcp"],
      "env": {
        "CODE_EXEC_EXECUTABLE": "/bin/zsh",
        "CODE_EXEC_INIT_COMMANDS": "source /Users/lazy/Projects/code-execution-mcp/.venv/bin/activate",
        "CODE_EXEC_LOG_DIR": "/Users/lazy/Projects/code-execution-mcp/logs"
      }
    }
  }
}
  • override timeouts
{
  "mcpServers": {
    "code-execution-mcp": {
      "command": "uvx",
      "args": ["code-execution-mcp"],
      "env": {
        "CODE_EXEC_FIRST_OUTPUT_TIMEOUT": "60",
        "CODE_EXEC_MAX_EXEC_TIMEOUT": "300"
      }
    }
  }
}

Manual installation

# Clone or download this package, then navigate to the directory
git clone https://github.com/agent0ai/code-execution-mcp.git
cd </path/to>/code-execution-mcp

# Install dependencies
pip install -e .

and run with config:

{
  "mcpServers": {
    "code-execution-mcp": {
      "command": "python",
      "args": ["</path/to/code-execution-mcp>/main.py"]
    }
  }
}

Available Tools

execute_terminal

Execute a terminal command in the specified session.

Parameters:

  • command (string, required): The shell command to execute
  • session (integer, optional): Session (terminal window) number (default: 0)

Output:

  • (string) The accumulated terminal output from the session

execute_python

Execute Python code via IPython in the specified session.

Parameters:

  • code (string, required): The Python code to execute
  • session (integer, optional): Session (terminal window) number (default: 0)

Output:

  • (string) The accumulated IPython output from the session

get_output

Get accumulated output from a terminal session.

Parameters:

  • session (integer, optional): Session (terminal window) number (default: 0)

Output:

  • (string) The accumulated terminal output from the session

reset_terminal

Reset a terminal session, closing and reopening it.

Parameters:

  • session (integer, optional): Session (terminal window) number (default: 0)
  • reason (string, optional): Reason for the reset

Output:

  • (string) Text confirmation for the agent

Session Management

  • Sessions (terminal instances) allow maintaining separate execution contexts for multitasking, persistence or context isolation
  • Each session can be used and reset individually
  • Sessions persist until reset
  • Session 0 is default
  • Any session number can be used

Virtual Environment Considerations

Important: When the MCP server is launched from a virtual environment, shell sessions may NOT automatically inherit the venv activation.

Solution: Use init commands to explicitly activate your virtual environment:

{
  "env": {
    "CODE_EXEC_INIT_COMMANDS": "source /path/to/venv/bin/activate"
  }
}

Platform Support

  • Linux: Fully tested and supported
  • macOS: Fully tested and supported
  • Windows: Experimental support via pywinpty
    • Some features may behave differently

Architecture

This MCP server is a minimal wrapper around Agent Zero's code execution tool:

  • Preserves Agent Zero's battle-tested logic
  • No rewrites or reimplementations
  • Uses Agent Zero's helper modules unchanged:
    • tty_session.py - TTY session management
    • shell_local.py - Local shell interface
    • print_style.py - Output styling and logging
    • strings.py - String manipulation utilities

Security

WARNING: This MCP server allows full code execution on the host system. Security is the responsibility of the MCP client.

Only use with trusted AI agents and in controlled environments.

License

MIT License

This project wraps and reuses code from Agent Zero (Copyright (c) 2025 Agent Zero, s.r.o), which is licensed under the MIT License.

See the LICENSE file for full license text and attribution details.

Credits

Built on Agent Zero's proven code execution implementation.

This MCP server preserves and reuses Agent Zero's battle-tested code:

  • Core execution logic from code_execution_tool.py
  • Helper modules: tty_session.py, shell_local.py, print_style.py, strings.py
  • All system message prompts

All credit for the robust code execution implementation goes to the Agent Zero team.

Uses FastMCP for MCP protocol handling.

Metadata

Release files for iflow-mcp_agent0ai-code-execution-mcp 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for iflow-mcp_agent0ai-code-execution-mcp 0.1.3
File Size Uploaded
iflow_mcp_agent0ai_code_execution_mcp-0.1.3.tar.gz 18.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for iflow-mcp_agent0ai-code-execution-mcp 0.1.3
File Interpreter ABI Platform
iflow_mcp_agent0ai_code_execution_mcp-0.1.3-py3-none-any.whl Python 3 none any Details

Total release size: 37.7 kB

Release files / iflow_mcp_agent0ai_code_execution_mcp-0.1.3.tar.gz

Download URL iflow_mcp_agent0ai_code_execution_mcp-0.1.3.tar.gz
Size 18.4 kB
Tags Source
SHA-256 checksum
How to use checksums
7d54cf4d337c677a196d849c298aac21c17e5d172a13b523b80b9b795c942d78
BLAKE2b-256 checksum
How to use checksums
3a59a8209ee11fe91aa455f14ee374e0537a4b3b71604e70da899463f9be8ab4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / iflow_mcp_agent0ai_code_execution_mcp-0.1.3-py3-none-any.whl

Download URL iflow_mcp_agent0ai_code_execution_mcp-0.1.3-py3-none-any.whl
Size 19.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
40324f363e40af7d82fe351959aa8d444e728424b05c5fd5abfc1a54a193210a
BLAKE2b-256 checksum
How to use checksums
da4b706877d0636870395aeacb214faf316ab3ac19c6e67ef7585c7c2629c46e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release history Release notifications | RSS feed

This release

0.1.3 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page