Code Execution MCP Server
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@Code Execution MCP Serverrun terminal command 'ls -la'"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
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, GPT-4, 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)
Related MCP server: TermPipe MCP
Installation
# Clone or download this package
cd code-execution-mcp
# Install dependencies
pip install -e .
# For Windows support
pip install -e ".[windows]"Configuration
The MCP server can be configured via environment variables:
# Shell executable (default: /bin/bash on Unix, cmd.exe on Windows)
export CODE_EXEC_EXECUTABLE=/bin/bash
# Init commands (semicolon-separated, run when creating new sessions)
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 timeMCP Client Configuration
Add to your Claude Desktop config (~/Library/Application Support/Claude/claude_desktop_config.json on macOS):
{
"mcpServers": {
"code-execution": {
"command": "python",
"args": ["/Users/lazy/Projects/A0-code-tool-MCP/code-execution-mcp/main.py"],
"env": {
"CODE_EXEC_EXECUTABLE": "/bin/bash",
"CODE_EXEC_INIT_COMMANDS": "source /Users/lazy/Projects/A0-code-tool-MCP/code-execution-mcp/.venv/bin/activate"
}
}
}
}Available Tools
execute_terminal
Execute a terminal command in the specified session.
Parameters:
command(string, required): The shell command to executesession(integer, optional): Session number (default: 0)
Example:
await execute_terminal(command="ls -la", session=0)execute_python
Execute Python code via IPython in the specified session.
Parameters:
code(string, required): The Python code to executesession(integer, optional): Session number (default: 0)
Example:
await execute_python(code="import sys; print(sys.version)", session=0)get_output
Get accumulated output from a terminal session.
Parameters:
session(integer, optional): Session number (default: 0)
Example:
await get_output(session=0)reset_terminal
Reset a terminal session, closing and reopening it.
Parameters:
session(integer, optional): Session number (default: 0)reason(string, optional): Reason for the reset
Example:
await reset_terminal(session=0, reason="Environment corrupted")Session Management
Sessions allow maintaining separate execution contexts:
Session 0: Default session for general commands
Session 1+: Additional sessions for isolated environments
Each session maintains:
Shell state (environment variables, working directory)
Command history
Output buffer
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
Install with:
pip install -e ".[windows]"Use
cmd.exeorpowershell.exeas executableSome 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 managementshell_local.py- Local shell interfaceprint_style.py- Output styling and loggingstrings.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.pyHelper modules:
tty_session.py,shell_local.py,print_style.py,strings.pyAll system message prompts
All credit for the robust code execution implementation goes to the Agent Zero team.
Uses FastMCP for MCP protocol handling.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections. Dates show when Glama detected each change.
No tool schema history has been recorded yet.
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Connectors
Operate Linux, macOS and Windows from your LLM. Every action runs through an auditable allowlist.
- mcp-serverOAuthai.cdbx
Build Apps and run code in 30 languages — sandboxed, with persistent sessions for agent loops.
Production-readiness for your AI coding agents.
Runtime permission, approval, and audit layer for AI agent tool execution.
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceEnables AI assistants to securely execute shell commands on local machines through an SSH interface with session management, command execution, and sudo support.1-
- AlicenseNot gradedqualityDmaintenanceProvides AI assistants with direct terminal access to execute commands, manage files, and run persistent REPL sessions. It features automated installation scripts that educate AI assistants on its capabilities for seamless integration.MIT
- FlicenseAqualityDmaintenanceEnables AI agents to start and manage pseudo-terminal sessions, run shell commands and interact with REPLs programmatically.7-
- AlicenseNot gradedqualityAmaintenanceEnables AI agents to securely execute terminal commands with persistent sessions, async jobs, and mission control, while providing a live dashboard for human oversight.4Apache 2.0
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/TerminallyLazy/A0-code-exec-MCP'
If you have feedback or need assistance with the MCP directory API, please join our Discord server