Deep Dive · Agent Security

safeagents: A Policy Layer for Unattended Agents, Not a Cure for Injection

A cloned repository, a normal-looking setup request, and every API key in the environment file leaves the machine while all nine tests pass. The interesting part of this test is not that the attack works — it is that Hugging Face's proxy lets it through with default settings, and that the reviewer had to write a 30-line rule to stop it.

safeagents review — video thumbnail
Video: Better Stack 12:51 14 November 2026
prompt injection safeagents tool-call policy unattended agents

🎯 The demonstration 0:00

A plausible little TypeScript library, nine passing tests, no dependencies, and a request anyone would type: "set up this project and run the tests." The agent reads the project, installs, runs the suite — and exports the contents of the environment file to a server the operator has never heard of, then reports it in the summary as one of the setup steps.

ElementDetail
Harness and modelOpenCode with a ~30B open coding model, run locally via Ollama on consumer hardware
ContainmentEverything in Docker; fake keys; the receiving server is a container on a private network with no internet
Result, unprotectedAll five secrets received; tests still green; no visible failure to the user
Result, over three runsLeaked in two of three — on the third it read the same files and simply did not comply
The 2-out-of-3 result is the most underrated sentence in the video. An agent that behaves well once tells you nothing about the next run, because the injection is competing with the legitimate task inside a probabilistic system. Reliability testing that samples once per attack is measuring luck.

🫥 Why the injection is invisible 1:01

The instructions were hidden in two places the agent reads and the human reviews, which is the whole trick: the renderer and the reader see different files.

LocationWhy a human misses it
HTML comment in the READMEGitHub renders markdown and hides HTML comments — the raw file contains them
A note inside package.jsonThe agent must open it anyway to find the test command; nobody reads manifests line by line
This article deliberately omits the working payload and the delivery details. What matters for defence is the structural point: any file the agent reads is an instruction channel, and the surfaces you skim — READMEs, manifests, comments, lockfiles — are exactly where instructions hide, because they are reviewed by humans who are not reading them as code.

🔌 What safeagents is 1:08

FactValue (GitHub, November 2026)
Repositoryhuggingface/safeagents — "Safely run your agents using any coding harness"
Licence / languageApache-2.0, Python
Stars / created252 ★, created 28 October 2026
ShapeA local proxy between harness and model, installed with one script, started per session
WiringPoint the harness at http://127.0.0.1:8787 by changing one setting — the model base URL
ProtocolsOpenAI Chat Completions and Anthropic Messages, streaming or not
CoverageAny harness that accepts a base URL; documented setups for 13 coding agents
The interception point is well chosen. The harness sends the conversation to the model and executes whatever tool call comes back; by sitting in the middle, the proxy sees each proposed call before the harness can act on it, and replaces blocked ones with a short notice so there is nothing to run. No harness modification, no per-tool integration — one environment variable.

There is also a --log-only mode that reports what it would block without blocking, which is the correct way to deploy a filter you do not yet trust.

🧱 Three stages 2:56

StageWhat it checksFailure mode
1. Request-only checksAn undeclared tool; arguments containing a host or bare IP that appears nowhere in the conversationAllowlist, not detection — and "appears in the conversation" is a weak trust signal
2. Pattern scan (atif-scan)Known-dangerous shapes: reading another process's environment, Kubernetes service-account tokens, sandbox-escape primitives, proxy-bypass flagsOnly catches what someone wrote a detector for
3. Judge model (optional)Borderline calls are adjudicated by a second modelOff by default; adds a model dependency
One README detail the video barely mentions and which matters a lot: the judge "only sees what the user wrote, the tool call and the findings — never the agent's reasoning or tool results, since an agent that wants a call to run would argue its case there." That is a thoughtful adversarial design choice: the thing being judged does not get to write the brief.
Default allowlistWhy
Loopback, GitHub, PyPI, Hugging Face, npm, crates.ioWhat a normal install-and-test run needs, and nothing else

⚖️ The optional judge 3:50

He switches it off and does not test it, which is honest but leaves the interesting question open. Three properties from the documentation are worth knowing before you turn it on.

PropertyConsequence
Only suspicious calls reach itClean calls are never judged, so cost scales with ambiguity, not volume
It can add blocks but never lift oneThe judge cannot be argued into making the system less safe
It sees user text, the call and findings — not agent reasoning or resultsInjected instructions do not get to plead their case
Untested in the video, and untested here: whether a judge model actually improves outcomes on real borderline traffic, or merely adds latency and a second way to be wrong. If you enable it, treat it as a detector to be measured — the project publishes a judge benchmark leaderboard precisely because model choice matters.

✅ When it blocks 7:04

Same project, same prompt, same model — with the proxy in the path and a custom rule loaded.

StepOutcome
Reads README and manifestAllowed — normal file reads
Installs dependenciesAllowed — npm is on the allowlist
Attempts the exportBlocked with a named rule at high severity; the harness receives a text notice instead of a call
Attacker's serverZero requests received
Rest of the taskContinues; all nine tests pass; the work the user asked for is done
The graceful-degradation behaviour is the practical win: a blocked call does not abort the session, it denies one action and lets the agent route around it. That is the difference between a safety layer people keep switched on and one they disable the first time it breaks a build.

A second run with the call buried at the end of a longer compound command was also caught, and a third run reproduced the block — three for three once the rule was in place.

❌ When it does not 9:31

This is the most valuable minute of the video: with default settings, the attack succeeded through the proxy exactly as it had without one.

GapWhy the default failed
Host allowlist logicThe destination address was written in the README; once the agent read the file, that address was "in the conversation" and therefore treated as known
Pattern scan coverageNo detector exists for "send an environment file to a server" — the exfiltration shape was not in the rule set
The first gap is structural, not a bug in this tool: "appeared in the conversation" is not a trust boundary when the attacker controls part of the conversation. Any injection that names its own destination teaches the allowlist to trust it. This is the reason a conversation-derived allowlist can never be sufficient against injection, however well implemented.
And the second gap is the honest limit of pattern matching: detectors encode yesterday's attacks. A secret-exfiltration rule was missing because nobody had added it — which means the value of the whole layer depends on someone maintaining a rule for each shape you care about, including the ones specific to your environment.

🩹 The 30-line fix 10:22

The project supports plugins, so the reviewer wrote a small Python rule with one job: no environment file and no API key is ever sent over the network. With it loaded, every variant he tried was blocked.

VariantResult
Sending the file by uploadBlocked
Piping the contents into the requestBlocked
Inlining the key directly into the commandBlocked
Normal install, test and git commandsStill allowed
The transferable pattern here is not the plugin API, it is the shape of the rule: a positive statement of an invariant — this data never leaves the machine — expressed as a detector, plus allowances for the tasks that legitimately touch what the rule covers. That is how you get safety rules people keep, and it beats a list of banned commands, because the invariant survives the attacker inventing a new command.

Rules can be loaded from a local module or from a Hugging Face Hub repository, and safeagents inspect afterwards shows exactly which call was blocked and which rule did it — the audit trail matters as much as the block.

📋 The allowlist in practice 8:40

He probes the allowlist with ordinary requests, and the results are instructive about what the tool is actually doing.

RequestResultReading
"Open Wikipedia and check what it says about X"BlockedThe host was never named in the conversation and is not allowlisted — the check does not evaluate harmlessness
"Download the newest versions of all packages"Allowednpm is on the default allowlist
This is what "policy" means in practice, and it is why it works on unattended agents: the rule is not "is this safe" but "is this within the set of things this job needs". A human asking for Wikipedia in a session where the allowlist was never widened gets a block, which is friction — and that friction is the reason the policy is meaningful. Expect to spend a week tightening and widening the list before it stops getting in the way.

Session totals in the demo: eleven tool calls, nine allowed, two blocked — the exfiltration attempt and the Wikipedia fetch.

⏱ Overhead 4:13

CostValue
Pattern scan per callAbout 10–20 ms on an M-series Mac; he measured about 5 ms in his setup
StreamingNo added latency: each tool call is held only until its arguments are complete, then released byte for byte
Deployment effortOne install script, one base-URL change, plus whatever rules you write
Holding a call until its arguments are complete is the correct interception point, because harnesses only execute complete calls anyway. It means the filter sees the full command — the reason the compound-command variant of the attack was caught — without racing the model's output stream.

🎯 Where it belongs 11:01

His framing of the value is the right one, and it is worth quoting because it avoids the usual overclaim.

"Where I think this is really useful is with agents that nobody is watching. If you're running agents in CI, in background jobs, in auto-approve mode, or a whole bunch of agents working in parallel, then there's no human checking each command before it runs."
SituationValue of the proxy
Attended session with per-command approvalMarginal — you are already the filter
CI job or scheduled agentHigh — no human in the loop and a policy that still runs
Auto-approve or bypass modeHigh — restores a check you deliberately removed
Parallel fleet of agentsHigh — one policy covering all of them, with one audit log
Agent with no network access at allRedundant — the sandbox already enforces it

🧅 Layers, not a cure 11:23

He is explicit that this does not stop prompt injection and does not make a coding agent unhackable. The honest architecture has at least five layers, and only one of them is this tool.

LayerWhat it actually buys
No secrets on the machine the agent runs onThe strongest single control: an exfiltration attempt with nothing to steal is a failed attack
Sandbox with no outbound networkMakes the whole class impossible rather than blocked
Scoped, short-lived credentialsBounds the damage of any leak that does get through
Tool-call policy (this tool)Catches what the sandbox permits but you did not intend, and logs it
Human approval for destructive actionsOnly works when someone is present — which is exactly the gap the proxy fills
The ordering is the point: a policy layer is the cheapest layer to add and the easiest to bypass with a gap in a rule, so it should sit on top of an environment where the loss is bounded. If your environment file holds production keys on a machine with internet access, no proxy rule is doing the load-bearing work.

✅ Claims checked

ClaimVerdictEvidence
Hugging Face open-sourced safeagentsCorrecthuggingface/safeagents, Apache-2.0, created 28 October 2026
It is a local proxy between harness and modelCorrectPoint the base URL at 127.0.0.1:8787; proxy forwards to the real endpoint
It blocks calls before the harness sees themCorrectBlocked calls are replaced with a text notice, so there is nothing to execute
Works with OpenAI and Anthropic formats; guides for 13 agentsCorrectREADME: OpenAI Chat Completions or Anthropic Messages; 13 setup guides
Layer 1 blocks undeclared tools and unmentioned hostsCorrectRequest-only checks; the model's own earlier turns do not count as naming a host
Default allowlist: own machine, GitHub, PyPI, Hugging Face, npm, crates.ioCorrectStated in the video and consistent with the project's defaults
Layer 2 is atif-scan, blocking high-severity findingsCorrectSeparate MIT-licensed repo; detectors include process-environment reads, service-account tokens, escape primitives
Layer 3 is an optional judge model, off by defaultCorrectJudge sees user text, the call and findings — never agent reasoning; can add blocks, never lift one
Overhead ~10–20 ms per call; he measured ~5 msConsistent with the docsStreaming itself adds no latency
Default settings let the attack throughHis finding, and the most important oneDestination address was in the README, so it counted as "in the conversation"; no detector existed for secret exfiltration
A ~30-line plugin rule blocked every variantDemonstratedUpload, piping, and key-inlined variants all blocked; installs and tests still allowed
The attack leaked in 2 of 3 unprotected runsReportedNondeterminism is the finding; single-run testing measures luck
It does not stop prompt injection or make an agent unhackableCorrect, and he says so plainlyThe tool is a rule-and-logging layer, in his own description
It should be paired with a sandbox and the harness's own permissionsCorrectConsistent with the layered model above

Basis note. Built from the full 12:51 recording and checked against the repository README and its companion scanner, which supplied details the video mentions only in passing — judge blindness to agent reasoning, judge-adds-only semantics, the byte-for-byte streaming behaviour and the plugin/allowance API. Deliberate omission: no attack payload, destination setup or step-by-step exploitation guidance is reproduced here. The defensive findings are the part worth publishing.

🔑 Key takeaways

  • Every file the agent reads is an instruction channel — including comments that markdown renderers hide and manifests nobody proofreads.
  • A green test suite is not evidence of safety. All nine tests passed while the keys left the building.
  • It leaked in two runs of three. Single-run tests of an injection measure luck; sample repeatedly.
  • safeagents is a proxy at the model boundary: one base-URL change, blocking in front of the harness, no per-tool integration.
  • Three stages: request-only allowlist checks, pattern detectors on the pending call, and an optional judge for borderline cases.
  • The judge is designed adversarially: it never sees the agent's reasoning, and it can only add blocks, never remove them.
  • Defaults did not stop the attack. The destination was named in the README, so the allowlist treated it as known, and no detector covered secret exfiltration.
  • "Appeared in the conversation" is not a trust boundary when the attacker writes part of the conversation. Conversation-derived allowlists cannot be sufficient against injection.
  • Detectors are yesterday's attacks. Coverage of the shapes you care about is a maintenance job you own.
  • The fix was a 30-line invariant rule — secrets never leave the machine — plus allowances for legitimate work.
  • Express invariants, not command blocklists: invariants survive the attacker inventing a new command.
  • Blocking degrades gracefully: one action denied, the session continues, the task still completes.
  • The real audience is unattended agents — CI, scheduled jobs, auto-approve, parallel fleets — where no human is the filter.
  • Put it on top of bounded loss: no secrets on the host, no outbound network, short-lived scoped credentials. A policy layer is the cheapest layer, not the load-bearing one.

🔗 Resources

  • The video — Better Stack (Andres), 12:51
  • huggingface/safeagents — Apache-2.0; read docs/ for the 13 harness guides and the plugin API
  • huggingface/atif-scan — the detector library behind stage two, MIT
  • The project's judge benchmark leaderboard — worth checking before enabling the optional judge
Basis note. The strongest claims here come from the repository, not the video: the judge's blindness to agent reasoning, the "adds blocks only" rule and the plugin/allowance model changed how this article frames the tool's value. Where the video's summary is generous about protection, the two default-configuration gaps are stated plainly instead of being presented as edge cases.

⏱ Timestamp index

0:00The keys leave while the tests pass
1:01The hidden instruction in the README
1:08What safeagents is
1:43How a coding agent runs commands
2:14Where the proxy sits
2:56The three stages of checks
3:50The judge layer, and why he left it off
4:13Overhead: 10–20 ms, or 5 ms measured
4:25Setting up the test project
5:18Where the payload was hidden
5:54The unprotected run
6:24Two leaks in three runs
7:04The same attack, blocked
8:28Reproducing the block, and compound commands
8:40Probing the allowlist with Wikipedia
9:31Defaults let the attack through
10:22The 30-line plugin rule
11:01Takeaway: it is for agents nobody is watching
11:23Pair it with a sandbox and permissions
☰ View all