execute_python
Run persistent Python code with state that survives across calls, supports top-level await, and uses the MCP bridge to call other tools in batch.
Instructions
Persistent Python REPL — use instead of python3 -c, heredocs or
cmd | python3 via Bash. Also the way to BATCH MCP WORK: the injected
mcp bridge reaches your project, global (user-scope) and plugin MCP
servers, so one loop replaces N separate tool calls —
for f in files: mcp.call('telegram-mcp', 'download_media', **f).
State (variables, imports, functions) survives across calls: a warm
call takes ~0.1s vs ~3s for each fresh python3 Bash spawn. Full
filesystem access — open(), absolute paths, and ~ all work. Top-level
await is supported (e.g. await client.get(url) with httpx).
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | Python code to execute | |
| reset | No | Clear namespace (keeps sh/mcp helpers) | |
| timeout | No | Max execution seconds (default 120). Enforced for real: runaway code is interrupted (KeyboardInterrupt) with namespace state preserved. |