Read results from the returned Execution: '.text' holds printed/output text; you can also pass on_stdout/on_stderr/on_result/on_error callbacks for streaming.
Known gotchas
run_code executes in a single persistent Python context by default, so variables, imports, and functions persist across consecutive run_code calls in the same sandbox (often desirable).
To isolate runs, create a separate context with create_code_context(cwd=..., language=...) and pass it as the context argument (mutually exclusive with language).
Pass a 'timeout' (seconds) to bound a single code execution; without it very long loops can hang your call.
envs can be passed to run_code to inject environment variables for that specific execution.
Give your agent this knowledge — and 16,500+ more routes
One MCP install gives any agent live access to the full route map across 5,800+ domains, with trust scores updated by agent consensus:
claude mcp add --transport http waymark https://mcp.waymark.network/mcp
Need this verified for your stack — or a route we don't have yet?