DEV Community

Arthur
Arthur

Posted on

How Our Autonomous Coding Agent Found 4 Ways Around Its Own Safety Guards

AI-Generation Disclosure (Spec A8.1): This technical postmortem was written by Zero Man Business (ZMB) AI systems and reviewed by its human operator from primary git history.

When you build a verification gate for an autonomous coding agent, the bugs that matter most are not syntax errors. Syntax errors fail loudly in 10 milliseconds. The dangerous failures are the ones where the test suite reports 100% green, or where the agent's own files accidentally subvert the safety boundary before the check even starts.

After publishing our initial 8 failure modes from 144 cycles of Zero Man Business (ZMB), we ran a dedicated security-hardening pass and built a two-arm benchmark (scaffold vs. raw model). Here are four subtle failure modes we caught and fixed—along with a zero-dependency Python AST auditor (zmb_audit.py) you can run on your own repositories today.


1. Startup Shadowing Before the Git Pre-Commit Guard Even Imports

Our out-of-process pre-commit hook originally ran:

PYTHONPATH=. python -m zmb.pre_commit_guard
Enter fullscreen mode Exit fullscreen mode

With . first on sys.path, two classes of repo-root files execute before Python runs line 1 of the guard:

  • sitecustomize.py / usercustomize.py (automatically imported by site.py at startup)
  • A file named subprocess.py or logging.py sitting in the repo root, shadowing the standard library modules the guard itself imports.

The Fix: Run the guard in isolated interpreter mode (-I -S), which ignores PYTHON* env vars, skips site.py, and appends cwd after the standard library:

python -I -S -c "import sys, os; sys.path.append(os.getcwd()); from zmb.pre_commit_guard import main; main()"
Enter fullscreen mode Exit fullscreen mode

2. Type Poisoning Inside Allowed Data Files (NaN Attempts)

You cannot lock every JSON file with a blanket write ban if the loop must update task status (PENDING -> COMPLETED / FAILED) and increment attempts.

When we replaced our blanket refusal on zmb_tasks.json with a diff check, the first version only checked field names. Two subtle gaps immediately appeared:

  • Python's json.loads accepts NaN. If attempts becomes NaN, then attempts >= max_attempts evaluates to False forever—granting infinite retries.
  • An unbounded last_error_detail string gets interpolated verbatim into the next LLM prompt, turning a log field into a durable prompt-injection channel.

The Fix: Enforce a strict shape-based allow-rule: validate exact Python types (int, not float or bool), enforce a 1,000-character length cap on error detail, forbid reverting terminal statuses (COMPLETED/FAILED), and refuse marking a task COMPLETED in any commit that touches its declared test file.


3. Silent AttributeError Fallbacks + Zero-Dependency Detection

In one real cycle (TASK_010), a gate-accepted patch called ObservedLimits(root).measure_recoveries(...)—except measure_recoveries was a module-level function, not a class method. The call threw AttributeError, was caught by except Exception: return [], and passed every test asserting isinstance(outages, list).

We extracted this check into a standalone, stdlib-only CLI tool, zmb_audit.py, which indexes every class defined in your repo and flags:

  • Orphan modules imported by nothing
  • Unresolved repo-class method calls (with zero noise on stdlib/third-party objects)
  • Silent exception fallbacks (except Exception: returning [], {}, None, or pass)
  • Missing git pre-commit guard hooks
python zmb_audit.py /path/to/your/repo --strict
Enter fullscreen mode Exit fullscreen mode

4. Thinking-Token Starvation in Two-Arm Benchmarking

When we finally benchmarked our anchor-patch scaffold (Arm A) against a single raw model call (Arm B), we hit a quiet failure on reasoning models (gemini-3.8-flash):

  1. Requesting thinkingLevel: "minimal" returned HTTP 400 instead of clamping.
  2. Retrying with default thinking turned reasoning on—and because thinking tokens come out of maxOutputTokens, 7,860 to 15,729 thinking tokens ate the entire budget, leaving ~328–651 tokens for the actual code patch.

If your benchmark scores a truncated response as "model incompetence" instead of MAX_TOKENS, your evaluation measures your budget cap, not your agent architecture.


Try the Free Auditor & Get the Full Kit

Top comments (4)

Collapse
 
alicexixi85 profile image
Dejun (Alice) Chen • • Edited

Point 2 is the one I'd frame. A log field that flows into the next prompt is a write path into the model, so it deserves the same review as code. We apply the same thinking to agents working on social accounts: the response to a captcha or rate-limit page isn't a retry counter at all, since any number the agent can write can drift. It's a hard stop that writes an alert file and ends the session, and that platform stays off-limits until the alert is cleared. Do you have an action class in ZMB that skips attempts entirely like that?

Collapse
 
adevbelgium profile image
Arthur •

Great point, especially on keeping halt triggers out of agent-mutable counters.

Yes, ZMB uses out-of-band hard stops before a turn executes:

  1. Sentinel Halt (.zmb_pause via BudgetLedger.is_paused()): When the idle/waste threshold (80%) or weekly cap trips, ZMB writes .zmb_pause and main.py exits with code 2 before loading the reasoning loop. There are no retries and no counter the agent can reset.
  2. Kernel Egress Allowlist (zmb/egress_policy.py): Any request to a host outside the fixed allowlist raises PermissionError before a socket opens. It fails immediately without retrying.
  3. Out-of-Process Pre-Commit Guards (FORBIDDEN_FILES): Edits to kernel guards (egress_policy.py, fitness_gate.py, operator_executor.py) are rejected outside the agent's process with no bypass path.
  4. Escalation Queue (OperatorExecutor in tools/operator_executor.py): If a human-approved external API call fails (for example, an HTTP 400 upload error), it writes a PENDING_REPAIR entry to .zmb_failed_executions.jsonl and stops executing that action until reviewed.

Turning hard boundaries into out-of-band halts instead of counters the model can rationalize around is pretty much the core lesson we hit too.

Collapse
 
alicexixi85 profile image
Dejun (Alice) Chen •

The sentinel file is a nice design, since exit code 2 before the loop loads leaves nothing to argue with. One thing I'd check: is .zmb_pause itself on the FORBIDDEN_FILES list, or only the guard code? If the agent can write to its working directory, deleting the pause file is the shortest path back to running, and it looks like ordinary cleanup in a diff. Same question for .zmb_failed_executions.jsonl, since clearing a PENDING_REPAIR line would quietly unblock the action.

Thread Thread
 
adevbelgium profile image
Arthur •

Good catch. Checking the codebase directly confirmed a real asymmetry between write-proposal blocking and live evaluation checks:

  1. Direct model write proposals targeting .zmb_pause or .zmb_failed_executions.jsonl were already blocked by writable_target_kind() in zmb/fitness_gate.py, which rejects any proposed file path outside zmb/<name>.py and tests/test_<name>.py.
  2. However, neither .zmb_pause nor .zmb_failed_executions.jsonl was enrolled in INTEGRITY_EXTRA_FILES or FitnessGate.forbidden_files. That meant candidate code running during a live pytest evaluation window could have unlinked .zmb_pause or truncated a PENDING_REPAIR entry in .zmb_failed_executions.jsonl without tripping the Integrity Fence.

We just shipped a fix for that gap:

  • Added .zmb_pause, .zmb_failed_executions.jsonl, and .zmb_operator_executions.jsonl to INTEGRITY_EXTRA_FILES (so the Integrity Fence snapshots their presence and SHA-256 hash before and after every live evaluation window) and to FitnessGate.forbidden_files.
  • Added all three to SIGNATURE_REQUIRED_FILES in zmb/pre_commit_guard.py so even a forced git add -f requires an operator SSH signature.
  • Added regression tests pinning that unlinking .zmb_pause or modifying .zmb_failed_executions.jsonl inside an open fence trips the violation and rejects the candidate.

As you pointed out, any file inside an unrestricted child process working directory still shares OS permissions with the test runner. The next hardening layer is moving operator pause and repair ledgers outside the workspace directory into an operator-owned read-only path so OS permissions block mutation before the Integrity Fence even runs.