Code execution: let the agent script multi-step tool work

The execute_code tool lets Hermes write and run a Python script that calls its own tools, collapsing many steps into one.

Docs-backedReviewed Oct 20, 2026

What Code execution is for

Instead of calling tools one at a time, Hermes can write a short Python script that calls tools such as web_search, web_extract, read_file, write_file and terminal, then run it with execute_code. That saves turns and tokens for repetitive jobs like processing a list of URLs or files. Scripts run with a timeout, a cap on tool calls and limits on captured output, and full output is saved to a cache folder. A project mode uses your project's Python environment, while strict mode uses Hermes's own interpreter and working directory. Secret-looking environment variables are stripped unless you explicitly pass them through.

What you need

  • Hermes on Linux, macOS or Windows
  • Python 3 inside the backend if you use a remote terminal backend such as Docker, SSH or Modal

Set it up

  1. 1

    Ask the agent to batch a repetitive task; it uses execute_code when a script is the better fit

  2. 2

    Adjust code_execution.timeout (default 300), code_execution.max_tool_calls (default 50) or code_execution.mode (project or strict) in ~/.hermes/config.yaml

  3. 3

    List any extra environment variables scripts need under terminal.env_passthrough

Check it works

  • Each result reports status, output, tool_calls_made and duration_seconds
  • Full stdout is saved under ~/.hermes/cache/exec/
  • Use hermes logs --level DEBUG to see whether environment variables were dropped

Limits and failure points

  • Scripts cannot call execute_code recursively, delegate_task or MCP tools, and terminal() calls cannot run in the background
  • Kernel state is lost on timeout or interrupt
  • Scripts can use Python's subprocess or os modules directly, which bypasses the shell command-pattern checks

Primary sources

Spotted something wrong or out of date? Tell us on X at @HermesWatcher (opens in a new tab) and we will fix it.

Want Hermes set up for you?

Setup help, custom agent builds and one-off projects. Tell us what you need and get a quote by email.