Engineering · Understand the implementation

Placeholders, not keys: how Mandu keeps secrets from AI agents

Coding agents read your keys as a matter of course. Mandu lets them work with placeholders instead, and puts the real value back only where you allow. This is how it does that at the operating-system level, without root.

Summary

  • Coding agents read your .env as ordinary work, and what they read goes to your AI provider.
  • Mandu hands the AI a placeholder for each secret it knows. The real value goes only to a host the secret is bound to or one you approve, a program allowed to open the file (such as ssh), your screen, and a model the file's level admits when the AI asks. Five checkpoints and one arbiter enforce this around an unmodified agent, without root.
  • In a live test on fifteen everyday tasks with Claude Code and Claude Sonnet 5.5, Mandu on a fresh install kept the secret and finished the task in 41 of 45 sessions, and with a rule written for each task in 43 of 44; the next best protection we tried, Claude Code's credential mask, in 27 of 45. We chose the tasks, some suit Mandu's design, and we improved Mandu on earlier runs of them. How we tested it.
  • Mandu does not stop prompt injection: a steered agent is held to each secret's rules, but a bound host gets the secret wherever the agent puts it, and anything else it reads, it can still send.

One key's trip

Ask an agent “how much did we charge on Stripe last week?” and it will look for the key the way you would: open .env, read STRIPE_KEY, call the API. Nothing about that is an attack, but without a protection two things happen to the key on the way. It reaches the AI provider: the file comes back as a tool result, which is part of the next model request and of every later one in the session. And it can go anywhere: a program the agent runs holds the real key and can send it to any host it names.

Here is the same question with Mandu running. The key's rule says no AI may read it and only api.stripe.com may receive it; that host is the key's binding. The arbiter is the one Mandu service that holds the placeholder table and makes every decision.

  1. The agent reads the file

    Claude Code calls its Read tool on .env. The result travels up in the next model request, through Mandu's model proxy. The proxy asks the arbiter about the file the tool opened; the arbiter knows it as a secret and creates placeholders, and the request continues to the AI provider with those in place of the values. The file keeps its shape and its keys:

    # what the AI provider receives for ~/proj/.env
    STRIPE_KEY='$MDU:nomodel_Read[9bbd].STRIPE_KEY'
    STRIPE_WEBHOOK_SECRET='$MDU:nomodel_Read[9bbd].STRIPE_WEBHOOK_SECRET'
  2. The AI writes a command with the placeholder

    curl https://api.stripe.com/v1/charges \
      -u '$MDU:nomodel_Read[9bbd].STRIPE_KEY:'

    The model proxy streams the response back and never resolves a placeholder in it. The agent runs the command as written, so curl itself only ever holds the placeholder.

  3. The request leaves through the egress proxy

    Programs the agent runs reach the network through Mandu's egress proxy. curl sends the pair as an Authorization: Basic header; the proxy decodes it, finds the placeholder, and checks the key's bindings. api.stripe.com is bound, so the proxy puts the real key in, re-encodes the header and sends the request on.

    # what Stripe receives
    Authorization: Basic base64("sk_live_51Hq…:")
  4. Anywhere else, it waits for you

    Had the command named another host, the proxy would have held it and filed a card on the dashboard's Approvals page: Allow once, Always allow, Send without it (the request goes out with [hidden by Mandu] in the key's place) or Block. In a session at a terminal the request waits up to a minute and your answer decides it; in a headless run or CI it is refused at once with a 403, and your answer applies to the next try.

  5. A program that needs the real key gets it, and is held to it

    ssh signs with your key; a deploy tool reads its own token file. A rule's readers name such programs, and on Linux in the confined posture Mandu's file guard opens the real file for that program alone, identified by its path and hash. Mandu gives the real bytes only to a reader it has checked does not print what it reads (ssh, ssh-add) or one you vouch for with prints: nothing. From then on it may connect only to the hosts the file is bound to, the files it writes carry the file's label, and what it prints reaches the AI as a placeholder.

  6. You see the real value

    When the agent tells you what it did, its reply passes through the reply filter, which resolves placeholders for your screen. You read the real key; the model's context keeps the placeholder.

Who gets the real value

For a registered secret, in secrets mode:

WhoGets the real value
YouAlways, in your terminal: the reply filter puts it back in what the agent shows you.
A host the secret is bound toYes, wherever the placeholder sits in the request. A login Mandu binds on its own (the npm and pip logins, Goose's key) goes only in the sign-in header.
Any other hostOnly after you answer Allow once or Always allow on the Approvals page.
A program allowed to open the fileYes, on Linux in the confined posture: ssh and ssh-add, or a program you vouch for with prints: nothing. It may then connect only where the file is bound.
Any other program the agent runsNo: it gets a placeholder copy when confined, and on macOS (read-blocked) the open is refused. In the gated posture it could open the real file.
A modelOnly when the file's level admits that model and the AI asks for it; never for a no-model secret.
Not masked at allThe agents' own sign-in variables, the login file of the agent you launched, and variables you exempt (below).

Two views, one invariant

Mandu keeps two views of everything the agent touches. In what the AI sees (AgentView in Mandu's design documents), each secret is replaced by a placeholder: a short, opaque token the AI can pass around, put in a command or a file, and reason about, but not read through, unless the secret's level admits that model and the AI asks for it. In what you and your programs see (HumanView), the real values are where they always were. Your terminal shows them, and a program allowed to open the file gets them.

Everything else follows from one invariant, which every change to Mandu is held to (the levels are below):

A secret (a registered credential, or a file or git object labelled above public) reaches a model only as an opaque symbol ($MDU:*) unless its level admits that model, and never leaves the machine unless a binding or the human allows it.

The design principle behind it is by construction, not by detection. Mandu does not scan the model's traffic for things that look like keys and hope to catch them. It takes the bytes out of the agent's world at the points where data enters and leaves it, and decides by provenance: which file a value came from, and which rule that file has. That is where it differs from the protections developers reach for today, which keep the file away from the task too, cover only the commands they wrap, or miss what their detectors do not know; Why a sandbox isn't enough to keep secrets from your AI provider compares them product by product.

Five checkpoints and an arbiter

Mandu does not modify the agent. It stands at the points where data enters or leaves the agent's world, and the arbiter decides. You start the agent through Mandu (mandu claude, mandu codex, mandu opencode, mandu openclaw, mandu goose), and the launcher wires each checkpoint into it. Claude Code, Codex and OpenClaw are supported; OpenCode and Goose are in preview.

YOUR AGENT AgentClaude Code, Codex,OpenCode, … Programs it runsshells, curl, git,python, … MANDU Model proxymasks secrets in tool results Reply filtershows you the real values Command sandboxread-only commands, no network File guardmasked copies of key files Egress proxyreal values where allowed Arbiterplaceholders, policy, events AI providerAnthropic, OpenAI, … Youyour terminal Your files~/.aws, ~/.ssh, .env The internetapi.stripe.com, … DashboardApprovals, Rules, Settings
The agent and everything it starts sit inside Mandu's checkpoints. None of them holds the placeholder table; each asks the arbiter.
CheckpointHow it attaches and what it does
Model proxyA local reverse proxy set as the agent's own base URL (ANTHROPIC_BASE_URL for Claude Code, a model provider entry for Codex), so no certificate tricks. It parses the Anthropic Messages API and OpenAI's Responses and Chat Completions APIs, relays only bodyless GET and HEAD requests otherwise, and refuses everything else. It classifies each tool result by the tool that produced it and the file or command it came from, and masks secret content; a value backstop also finds registered values inside results that would otherwise pass as public. Responses stream back without resolving any placeholder.
Egress proxyA forward proxy set as HTTP_PROXY and HTTPS_PROXY for every program the agent runs. In secrets mode it inspects TLS with a per-session certificate authority the agent's tools are told to trust (curl, Node, Python, git); model hosts get a blind tunnel. It finds placeholders in the URL, the headers, the body and the decoded Basic credential, and puts the real value in only for a host the secret is bound to, or one you approve on the Approvals page.
File guardA program the agent runs that opens a credential file gets a placeholder copy, served by a seccomp guard on the open family. Where unprivileged namespaces are available, a mount of the copy over the file adds a second layer. Programs allowed to read the real file are identified by their executable, pinned by path and hash.
Command sandboxRead-only commands (cat, grep, sed, awk, jq, find and the like) run in a Bubblewrap box with no network, every capability dropped, fresh namespaces and a seccomp deny filter, where the host allows unprivileged namespaces.
Reply filterResolves placeholders in what the agent shows you. Interactive terminal apps are relayed through a pseudo-terminal, and when a full-screen renderer splits a placeholder across repaints, a model of the screen's cells reads it back and repaints it with the value.
ArbiterHolds the placeholder table (a single-writer SQLite database), applies your policy and records every decision for the dashboard. Checkpoints reach it over a Unix socket. The operations that show you real values are served on a second socket the agent cannot reach; reading an any-model or local-model file's content is still one call away on the first, and moving it is a known follow-up. Mandu's folder, ~/.mandu, is hidden from the agent.

Every checkpoint but one fails closed. If the model proxy cannot reach the arbiter it answers with an error and forwards nothing; the egress proxy blocks; the file guard keeps the placeholder. The exception is the reply filter, which only ever shows you data: if it fails, you see placeholders, and nothing leaks.

A program can ignore HTTPS_PROXY. Two kernel layers sit under the proxy for that case: a seccomp trap on connect and sends, and a Landlock allow-list of ports for the whole agent. In the confined posture such a program holds only the placeholder, so that is all it can send. The exception is a program allowed to open the file: it holds the real bytes, and Mandu's guard lets it connect only to the hosts the secret is bound to.

The placeholder format

The placeholder from the first step of the trip has five parts:

$MDU:PrefixMarks a Mandu placeholder
nomodel_Model accessNo AI may read this secret
ReadToolHow it reached the AI (Read for the agent's file tool)
[9bbd]IDRandom, unique in the local table
.STRIPE_KEYSecret nameWhich value in the file

A few choices in that format matter more than they look.

  • The ID is random, not a hash of the value. Four hex characters, checked for collisions when the arbiter writes the row. Because nothing in it is derived from the value, it says nothing about what it stands for. Every field of one file shares the file's ID, so the names read as fields of one file.
  • The file keeps its keys. Only the values are replaced, so the AI can still tell you which variables exist, and . ./.env still works. Our first live run masked whole files instead. It kept every secret, but many tasks failed: anything that parsed the file got one opaque token, so sourcing .env failed, a script found no variable names, and a deploy script ran with an empty key.
  • The level marker is for the reader. nomodel_, localmodel_ and anymodel_ tell the AI what it may do next. Decisions read the table, never the name, and the markers are reserved, so a tool named like one cannot forge a level.
  • The quotes are deliberate. A placeholder starts with $, which a shell would expand as a variable. Mandu single-quotes the placeholders it writes into a file like .env, and when a shell strips one anyway, the egress proxy refuses the request and tells the agent to use single quotes.

Who may read it, where it may go

Mandu finds secret files by place, not by shape. A built-in catalog covers the stores developers keep keys in (~/.ssh, ~/.aws, ~/.config/gcloud, ~/.kube, ~/.netrc, .env files, private keys, service-account files, Terraform state and dozens more), and you label anything else in ~/.mandu/policy.yaml or on the dashboard's Rules page. Environment variables are masked by name (*_TOKEN, *PASSWORD and the like) or by a known key format. Pattern detectors help decide which values inside a registered file are masked, and drive a scan that reports keys in your workspace and git history, but they never mask a tool's output on their own.

Each labelled file answers two questions. Which AI may read it is its level:

LevelOn the dashboardWho may read the content
no-modelNo AINo model at all: only you and the programs allowed to open it (ssh and ssh-add for SSH keys, or a program you vouch for with prints: nothing). The level the catalog gives credential files.
local-modelYour own AI onlyOnly a model you declare as your own (local: true), such as an Ollama on this machine. Mandu never decides that from an address.
any-modelAny AI, when it asksAny model, when it asks. Reading it into the conversation is recorded, and changes what the session may do next.
publicNot secretAnyone. The default for ordinary files.

Where it may be sent is its bindings, which the dashboard calls listed hosts: the hosts that get the real value without asking. A host covers the hosts under it, *.example.com only those under it, host:443 that port only. Programs that may open the real file are its readers. Mandu gives the real bytes only to a reader it has checked does not print what it reads (ssh, ssh-add) or one you vouch for with prints: nothing; any other reader you name gets the placeholder copy.

# ~/.mandu/policy.yaml
paths:
  - path: ~/proj/.env
    level: no-model
    values:
      STRIPE_KEY: { bindings: [api.stripe.com] }
  - path: ~/.ssh/id_ed25519
    level: no-model
    readers: [{ app: ssh, from: git }]
  - path: ~/notes/board-minutes.md
    level: local-model
models:
  - name: ollama
    url: http://127.0.0.1:11434
    wire: openai-chat
    model: llama3.2
    local: true

Two refinements keep this honest once real programs are involved.

  • A program that read two secrets may send only where both may go. When Mandu lets a program open the real file, it marks the process before handing it the file descriptor. The mark only grows, is inherited by children and follows pipes and socket pairs, and the program may connect only to hosts that every file it has read may reach. An early version took the union instead of the intersection, which would have let a process holding both .env and ~/.aws/credentials send the AWS key to Stripe.
  • A session that read a secret's content into the conversation is marked for the rest of the session. The AI has two tools for an any-model file (they keep the code's word for a placeholder, symbol). inspect_symbol has a separate, quarantined model read the content and answers with a new placeholder, so nothing changes. declassify_symbol reads the content into the conversation, and since what the AI writes afterwards can carry it in words no placeholder marks, from then on only the content's bound hosts go without asking. Every other request and every shell command waits for you, and the files the session writes are marked secret for the next one. Passing a placeholder along never marks a session, and neither does a no-model file, which the AI never reads.

Enforcement without root

Mandu runs as your user. It uses every unprivileged kernel mechanism that helps, turns each on where the running kernel supports it, and says so plainly where it does not.

  • seccomp user notification (Linux 5.0 and later) to intercept opens, connects and sends. Mandu's guard does the open itself and hands the descriptor back (SECCOMP_IOCTL_NOTIF_ADDFD, 5.9), and connects through pidfd_getfd (5.6), so a check cannot be raced.
  • Landlock to confine file access (5.13) and TCP ports (6.7).
  • Unprivileged user and mount namespaces for the second file layer and the command sandbox, with no_new_privs and every capability dropped.

Anything that needs root or changes the host for other users (host-wide firewall rules, a virtual machine run as root) is out of scope by design, not deferred. The one exception is optional: on Ubuntu, where unprivileged namespaces are restricted, a one-time mandu setup asks for your password to install Mandu's own Bubblewrap with a permission for that copy alone. Every launch reports a posture, and mandu doctor explains it:

PostureWhereWhat holds
confinedLinux x64 with Mandu's native guard, including a stock Ubuntu 24.04 or 26.04 with no sudoPrograms the agent runs get a placeholder copy of each credential file, except the readers allowed for it (ssh and ssh-add for your SSH keys by default, and programs you vouch for), which get the real file and may connect only where it is bound. cat ~/.aws/credentials shows a placeholder.
read-blockedmacOS (experimental)Programs the agent runs cannot open your credential files at all.
gatedAnywhere elseThe model never sees a registered secret and Mandu checks what leaves, but a program the agent runs could open a credential file. --require-confinement refuses to start instead.

What it costs. Mandu needs Linux x64 (or macOS, experimental), Node.js 22.13 or newer and git. Each launch brings up the arbiter, two model proxies and the native guard, which takes about three seconds. We have not yet measured per-request latency or token overhead against a real model.

Threat model and scope

The adversary is the agent itself, driven by whatever text it reads, together with every program it runs, with your own permissions on a machine you control. It may run arbitrary code, including native code, and try any system call, but it cannot escape the unprivileged user namespace or the seccomp filter installed before it started. The AI provider is honest but must not be trusted with the bytes, so every claim here is about what reaches the wire, not about what the model promises.

You are trusted: your terminal shows real values, and you change rules and answer approvals on a channel a confined launch's programs cannot reach (a launch with neither the guard nor the mount layer, or with Protection off, lets its own programs reach it, and a confined launch started beside one warns). So is the kernel; an attacker who already has root is out of scope. The claims hold for registered secrets (the catalog, your labels, matching environment variables), in secrets mode (Protection on, the default; the other product mode, off, only records), and at full strength in the confined posture described above.

What Mandu does not do

A security tool is only as useful as the list of what it does not cover. The full list is in What Mandu guarantees, and what it does not (on GitHub); these are the ones most likely to matter.

  • Prompt injection. An instruction hidden in a web page can still steer the agent to send out something that is not a registered secret, such as your source code. Registered secrets stay protected when that happens; nothing stops the steering itself.
  • A bound host gets the value wherever the agent puts it. If you bind a key to a host that publishes what it receives, the agent can be made to publish it there.
  • Unregistered secrets are not secrets. A key pasted into notes.txt is ordinary text until you label the file.
  • The agent's own sign-in is not masked. ANTHROPIC_API_KEY, ANTHROPIC_AUTH_TOKEN, ANTHROPIC_CUSTOM_HEADERS, CLAUDE_CODE_OAUTH_TOKEN, OPENAI_API_KEY, CODEX_API_KEY and the others the user guide lists stay as they are, because the agent needs them to reach its model, so the AI can read them. The login file of the agent you launched is left as it is too, and the programs it runs read it. So is a variable you exempt in policy.yaml.
  • Some database logins need a workaround. SQL shells can print files, so they never get the real credentials file; since 25 October 2026 the network proxy answers a Postgres or MySQL server's password check with the real password instead. A MySQL client that checks the server's certificate against your own CA refuses the proxy, and a login from PGPASSWORD or MYSQL_PWD waits for your OK unless a rule binds the variable to the database's host.
  • A program you allow can leak what it reads, for instance by printing it in an encoding, or through file names, sizes or timing. Mandu makes no non-interference claim.
  • After declassify_symbol, the guarantee drops from the model never saw it to the session is confined: the content is in the model's context, and what the session sends is held to the content's bindings and your OK.
  • Edits to a protected file do not stick. A program that is not an allowed reader writes to the placeholder copy; the change is discarded when the session ends, and Mandu names each file it discarded.
  • Platforms. Linux x64 with the native guard is confined. macOS is read-blocked and experimental. Windows has no secret protection. Programs that pin their own certificates fail rather than leak (except kubectl, helm and Java, which the proxy connects itself), unless you list them as readers, which then hold the real bytes and connect directly to the bound host.
  • Mandu itself is attack surface. The supervisors parse what the agent's programs do, the arbiter's socket is reachable, and the egress proxy terminates TLS and holds real values.

Nothing here is formally proved. A formal model of the contracts is a working draft; today the evidence is tests. Every path by which data enters or leaves the agent must ship with an end-to-end test asserting that no unmasked secret reaches a model it is not cleared for, or the network, and the checkpoints' fail-closed behavior is tested. The maintainers' CI runs the suites in a throwaway virtual machine on every push, and scripts/ci/vm-run.sh runs the same suites on your machine. To see what a launch would mask on yours, run mandu doctor --secrets.

How it held up

On 19 October 2026 we ran Claude Code with Claude Sonnet 5.5, live, on fifteen everyday tasks that touch a secret, three takes of each, under Mandu in two settings, six other protections and no protection: 450 sessions. Mandu on a fresh install kept the secret and finished the task in 41 of 45 sessions, and Mandu with a rule written for each task in 43 of 44; the next best, Claude Code's credential mask, in 27 of 45. Counted only over the tasks both can win by design, Mandu (a rule for each task) did both in 40 of 41 sessions and the mask in 27 of 42.

We chose and wrote the tasks, and some suit Mandu's design: the blood-test summary needs a model on your own machine, which only Mandu can route a read to. We improved Mandu on earlier runs of these same tasks; a fresh install still asked the person 42 times over 45 sessions, where the other protections never ask; and it is one agent, one model and one day. Every setting ran with Claude Code's permission prompts off. The method, the head-to-head, what each protection did and every caveat are in Secret kept, task done.

Where it comes from

Mandu builds on our experience with Prompt Flow Integrity (arXiv:2503.15547) and DualView (arXiv:2607.03821), two defenses against indirect prompt injection that work inside an agent framework. Mandu sits at the operating-system level instead, so it works with agents that know nothing about it. Today it applies its placeholders to secrets. A prompt-injection defense, which would do the same for untrusted text, is in the code but frozen and experimental: it runs only when explicitly enabled.

Mandu's code is under the Apache-2.0 license. The code, the design documents and the guarantees are at github.com/mandusec/mandu, starting with How Mandu works; to report a vulnerability, see SECURITY.md.

To compare the ways of keeping secrets from an AI agent, read Why a sandbox isn't enough to keep secrets from your AI provider. For how we tested it and what the test does not show, read Secret kept, task done.

Changes

  • What Mandu does not cover: database logins, and kubectl, helm and Java behind a pinned certificate, now work through the network proxy, with the cases it still cannot fill in.
  • How it held up reports the new run (fifteen tasks, Mandu with a rule for each task and as a fresh install, six other protections, keys in the real shape), with its counts and the head-to-head over the tasks both sides can win; the earlier run on six tasks is superseded.
  • How it held up now gives the evaluation's results in words, without counts, because several of its tasks suit Mandu's design. Where it comes from now says, in short, that Mandu builds on our experience with Prompt Flow Integrity and DualView.
  • The evaluation moved to its own post, Secret kept, task done, with a correction: the test API keys were not in the shape real keys have. One key's trip now comes first, with a step for the programs allowed to read the real key and a table of who gets it; the statements that programs never get your keys now name the readers that do.

← All engineering posts