Security By Hsin, Head of Product

Your coding agent reads your secrets. Keep them out of the model.

Ask a coding agent to fix a failing test and it will read the test, the code under it, the config next to it and, quite possibly, the .env beside that. Everything it reads becomes part of the next request to its model provider. Not because the agent misbehaved: reading is the job, and the model can only reason about what it has been sent.

Where this comes from: we build an agent runtime, and what follows is how ours handles this, released in the open source (v0.142.0 is the current release). It protects against a cooperative agent leaking by accident, not a determined one leaking on purpose. That limit is spelled out near the end, and it isn't small. Corrected on 28 November 2026: the first version of this post named v0.141.1, which was never released, called the hook impossible to switch off, and said every failure blocks. Both claims overstated it. The sections on making it stick and on what it does not catch now say exactly where the limits are. Updated on 29 November 2026: v0.142.0 redacts a failing shell command's output in sessions where a settings file allows all of Bash or permissions are bypassed. The cases it still misses are in the list near the end, which now also says that the agent's own replies are not scanned.

Why the usual answer doesn't reach this

The usual answer to "keep secrets away from the model" is a gateway: put a proxy between your applications and the model API, and scrub requests on the way out. It is a good control for applications you build.

A coding agent like Claude Code usually talks to its model provider directly, from wherever it runs. Its requests never pass through your gateway, so the gateway never sees the API key in the log file the agent just opened, the customer email in the CSV it sampled, or the private key it cat-ed while debugging TLS.

The only place that sees all of that is the agent itself, at the moment a tool returns. That is where we put the redaction.

We are not the first to put redaction in a hook. Projects such as secretgate and redact-hook do it too, and if you want this on your own laptop, one of them may be all you need. What we add is aimed at a team handing boxes to agents: the hook can be installed by the platform rather than by each user, it fails closed before a tool runs instead of falling back to the unredacted result, and secrets are never kept, so they are never put back.

Redact where the agent reads

Claude Code runs hooks: programs it calls at fixed points with the event as JSON, whose answer it obeys. containarium guardrail hook <event> is one such program. Detection, the redaction key and the map of redacted values all stay on the machine the agent runs on; it reads no credential and calls no server.

What the guardrail hook does at each Claude Code event
EventWhat the hook does
SessionStartTells the model what a redaction marker is, and that it can't be written into a file.
PreToolUseThe gate. Restores personal-data markers in file paths and in edits, so code the agent writes uses the real value. Refuses any call that would write a secret marker, or a marker this machine never issued. Denies WebFetch, which hands a page to the model before any hook could look at it.
PostToolUseReplaces the tool's result with a redacted copy of the same shape, for every tool, including ones it has never seen.
PostToolBatchRescans what is about to reach the model, and records anything still unredacted.
UserPromptSubmitBlocks a typed prompt that contains a finding, naming the type and never the value. A prompt can be blocked, but not rewritten.
InstructionsLoadedScans instruction files and records findings; this event can't change anything.

Markers that keep code working

A finding is replaced by a marker such as [[EMAIL:1a2b3c4d5e6f]]: the type, then 12 hex characters of an HMAC over the value under a key that never leaves the machine. The same value always gets the same marker, so the model can still see that two files refer to the same customer, without learning who the customer is.

The two kinds of finding are treated differently, and the difference is the point:

Making it stick, and how it fails

A hook in a user's own settings can be switched off by that user with one line (disableAllHooks). That is fine on a laptop and wrong on a box an organization hands to an agent. So the daemon can install the hook as a Claude Code managed-settings drop-in, which user, project and local settings cannot disable.

That is tamper-evident, not tamper-proof. A box user with sudo can remove or change the drop-in, the binary or the engine. The daemon checks coverage on a schedule and reports a box whose hook is gone or changed, but a user who removes it and puts it back between two checks goes unseen.

The switch is per box, and it belongs to the operator:

# admin: write the managed drop-in into a box, and again at every start
containarium guardrail dropin enable <box>

# the box's tenant or an admin: is this box actually covered?
containarium guardrail dropin coverage <box>

Before it writes the drop-in, the daemon copies its own statically linked binary into the box, runs it once as the box user, and starts a local detection engine on a unix socket. If any step fails, the box reports itself as not covered and gets no drop-in, rather than a half-installed hook that blocks every tool call. New boxes start with the switch off; whoever creates boxes that must be covered turns it on.

Before a tool runs, failure blocks. If the engine hasn't answered within 3 seconds, the tool call is denied. An internal error exits with status 2 and no output, never 0, because a hook that exits 0 with unusable output is not caught by Claude Code's onFailure: "block". After a tool has run, the hook can only degrade, not undo. If the engine fails, or a result is over 16 KiB, the result gets the in-process pattern pass and is recorded as partially scanned. A hook that crashes at that point cannot stop the original result reaching the model.

What this does not catch

This list is longer than the feature list, and it should be. The hooks protect against accidental disclosure by a cooperative agent. They do not stop an agent that deliberately transforms a value (base64, reversed, split across calls), or the user, who owns the machine.

The detector is the weak part, on purpose

Everything above is plumbing: where the hook sits, how markers work, how it fails. None of it decides what counts as a secret. That is the engine's job, and the one in the open source is deliberately modest: a handful of regular expressions (email, US phone, US social security number, IPv4, Luhn-checked card numbers, PEM private keys, one cloud access-key shape). It exists so the flow runs end to end on a fresh install. It is not a detector to rely on, and the CLI says so every time it's used.

A real engine (rule packs, NER models, per-language recognizers) plugs in behind a small gRPC contract on a local socket. We don't have a public engine for that contract yet, so today what you can run is the plumbing plus the regexes. We have measured how much that matters: on a mixed English and Traditional Chinese test set, one release of an external engine missed every Traditional Chinese identifier, and the next release caught all of them while still missing international phone formats, passports and a spaced IBAN. The plumbing did not change between the two runs; the engine did. "No findings" is a measurement, not a proof.

Trying it

On a self-hosted Containarium install at v0.141.2 or later (v0.142.0 or later to redact failing shell commands, under the conditions in the list above), enable the drop-in on a box and check coverage, as above. Outside a box, the same handler works in any Claude Code settings file, as long as the containarium binary is on the machine. Configure every event in exec form, with a short timeout and onFailure: "block" (Claude Code 2.1.295 or later):

{ "type": "command", "command": "containarium",
  "args": ["guardrail", "hook", "PreToolUse"],
  "onFailure": "block", "timeout": 15 }

Repeat it for SessionStart, PostToolUse, PostToolBatch, UserPromptSubmit and InstructionsLoaded. In a user settings file it can be switched off; that is what the managed drop-in is for. The full design, including every limit above, is in docs/architecture/guardrail.md.

Keep reading

Give the agent a box, not your laptop.

Self-host the open source on your VM, or get a seat on the hosted cloud.