Your harmless Python command got blocked — here's what the guard actually scans

Eleven at night, you ask the agent to summarise that big JSON export. It writes an unremarkable four-line command: timeout 600 python3 - <<'EOF' — open report.json, load it, print a few counts. And it comes back refused: “the script this command executes must be scannable (a regular text file under 1 MiB)”. You stare at it. report.json is data. Nothing is being executed.
The guard itself is not paranoia. Hermes’ gateway is a long-lived process: every cron tick, desktop turn and chat turn runs inside it. If a command restarts the gateway from the inside, the process gets SIGTERM, the supervisor revives it, auto-resume replays the same turn — a self-inflicted restart loop. So cron/lifecycle_guard.py refuses those commands, and it does not stop at the command string: it walks the scripts the command executes, and any executed script must be scannable plain text under 1 MiB. Failing closed is the right policy.
What went wrong is the “who executes what” judgement. PR #160584, merged November 27, fixes that judgement.
Who owns a heredoc: the parsing problem nobody budgets for
A heredoc is shell syntax: <<'EOF' means “everything up to EOF is standard input for the command before me”. But that body is not going to the shell — it is going to python3, as data. So the guard has to mask those bodies before scanning what remains; otherwise open('report.json') inside the body looks like “you want to execute report.json”.
Masking is dangerous in the other direction: mask too much and someone hides bash inside a body. So tools/shell_heredoc.py is deliberately narrow. A body is masked only when all of these hold:
- every heredoc delimiter is quoted (
<<'EOF', never<<EOF); - there is an exact terminator line;
- the command that owns the heredoc is an allowlisted non-shell interpreter (
python,python3,osascript,cat), preceded only by environment assignments, a bareenv, and wrappers that take numeric or flag operands only (timeout,nice,nohup,stdbuf,ionice); - nothing but pipes follows the heredoc on that line;
- every command those pipes feed is a bare-name text filter (
grep,head,tail,uniq,wc,cut,tr,column,jq,cat) —| bashand| ./grepdo not count.
The old parser missed two of those. It recognised the owner only when the interpreter was the first word of the line, so timeout 600 python3 fell through. And any | after the heredoc dropped the masking entirely. The body was then walked as shell, the path inside open('report.json') became an “executed script”, and a 2.4 MB data file could never pass a 1 MiB scan cap.
Before and after: same body, different verdict
The PR measured real scan_gateway_lifecycle(cmd) output. Left is origin/main, right is the fix:
| Command | Before | After |
|---|---|---|
timeout 600 python3 - <<'EOF' reading a large JSON |
Refused: file over the scan cap | Allowed |
python3 - <<'EOF' 2>&1 | grep -v x |
Refused: same | Allowed |
nice -n 5 python3 - <<'EOF' | head -n 3 |
Refused: same | Allowed |
python3 - <<'EOF' (no wrapper, no pipe — control) |
Allowed | Allowed |
And nothing genuinely dangerous loosened:
timeout 5 bash <<'EOF'withbash bigfilein the body — still refused;cat <<'EOF' | bash— still refused;cat <<'EOF' > run.sh; f=run.sh; bash "$f"— still refused;cat <<'EOF' | sort --compress-program=sh— still refused;python3 - <<'EOF' | ./grepwhere./grepis a local executable — still refused.
One detail worth keeping: the first revision of this PR let four write-then-run variants through. An independent review caught them, each was confirmed to really execute the body (with a harmless printf marker standing in for the restart), and all were closed. That is the shape of a good security fix — widen only where the body is provably data. cat is the only consumer whose body is pure data; a python body is masked for UX-grade scanners but a security-grade scan still reads it whole, because os.system reaches a shell at runtime.
If you get refused (don’t disable the guard)
First check two things: is the file really just data, and is this running inside the gateway? Then rewrite in this order — the second one usually does it:
- Pass the big file as an argument instead of naming it inside a heredoc. Keep a small script on disk (plain text, under 1 MiB) and run
python3 summarize.py report.json. The script is scannable; the data file is an argument and needs no scan. - Drop the wrapper.
python3 - <<'EOF'withouttimeout/nicepasses today. If you were only guarding against a long run, a process timeout or moving the job to the background triggers fewer parser edges than wrapping it. - Split the line.
cat <<'EOF' | grepis fully supported. What is not supported is anything after the heredoc that could run what the line just wrote:;,&&,||,&,bash,./something. - Don’t try to launder it. The guard exists to stop the gateway restarting itself; getting around it means SIGTERM for the whole process group. If a restart is genuinely required, run
hermes gateway restartfrom a shell outside the gateway — that is the designed path.
Cron jobs go through the same judgement: the script and the prompt’s commands are scanned when the job is created. So if you are writing a scheduled job with a heredoc in it, try the command in a local shell first rather than discovering it at save time. The cron doctor guide and unattended approvals cover the neighbouring failure modes.
Status and scope
The fix is on main only; it is not in the v0.23.4 stable package (its release page does not list it). A stable install still treats timeout ... python3 - <<'EOF' as suspect.
Update (2026-11-28): these changes shipped in v0.23.5 (November 28) —
hermes updatebrings them in. The “not in v0.23.4 / onmainonly” wording above is a snapshot from publication time.
The scope is worth stating plainly. The guard only runs inside a supervised gateway process — when the terminal tool executes there, and when a cron job is created. Your own shell is not affected. And it is not a sandbox: it prevents one specific accident (restarting the gateway from within), not malicious code. Isolation is the sandbox backend’s job. Keeping those two ideas separate is what stops a false positive from becoming “let’s just turn the guard off”.