A Python execution tool for agents, with each MCP session assigned its own isolated Docker container.
Go
MCP
Python
Docker
I built Code Executor MCP as a Go server using MCP’s Streamable HTTP transport. Its execute_python tool accepts Python code and optional package requirements, then returns the program’s standard output.
Session lifecycle#
sequenceDiagram
accTitle: A Python execution session
accDescr: The MCP server assigns a dedicated container, returns the Python program's output and destroys the container when the session ends.
participant C as MCP client
participant S as Go server
participant D as Container
C->>S: Open session
S->>D: Reserve from pool
C->>S: execute_python
S->>D: Run Python offline
D-->>S: Standard output
S-->>C: Tool result
C->>S: End session
S->>D: Destroy container
The client can call execute_python repeatedly in the same session. If a call requests packages, the server installs them with uv before disconnecting the network and running the code. Calls are serialised, and installed packages stay in that session’s container until it is destroyed.