# 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.

Canonical: https://hermeswatcher.com/tools/code-execution  
Kind: Capability · Skills, plugins & MCP  
Last reviewed: Oct 20, 2026  
Basis: Explained from the official Hermes Agent docs and repository (Nous Research). Steps follow the linked official sources.

## What it 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

## Setting it up

1. Ask the agent to batch a repetitive task; it uses execute_code when a script is the better fit
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. List any extra environment variables scripts need under terminal.env_passthrough

## How to 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

- 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

## Related workflows

- [Collect content ideas without losing the evidence](https://hermeswatcher.com/workflows/content-research-queue.md)

## Sources

- [Hermes Agent docs: Code Execution](https://hermes-agent.nousresearch.com/docs/user-guide/features/code-execution)
- [Hermes Agent docs: Security](https://hermes-agent.nousresearch.com/docs/user-guide/security)

---

HermesWatcher is an independent guide. It is not affiliated with or endorsed by Nous Research. The [official Hermes Agent documentation](https://hermes-agent.nousresearch.com/docs) and [repository](https://github.com/NousResearch/hermes-agent) from Nous Research are the authority; each page here lists the official sources it was written from. If this site and the official docs disagree, trust the official docs. Index for agents: https://hermeswatcher.com/llms.txt
