Threat model for an agent — study guide

The concept's fragments, read in order.

For your capstone Run a coding agent you don't have to trust

Every control around your agent answers a line on one page you write before the controller: the assets (code, credentials, production, the record), the parties, and a boundary drawn around the controller and you, with the agent outside it.

Say the agent takes task T-12, reads the issue, the file src/dates.py and a test fixture, proposes a patch, and ends with 2 files changed, all tests pass. Your page sorts each piece. The patch is a proposal the controller checks before anything acts on it. The fixture is text that may carry instructions, however much it looks like data. The closing line is a claim until the controller runs the tests itself.

Decide what you trust before you build

Every control you put around an agent answers a question you have to settle first: what you are protecting, who you are protecting it from, and what you refuse to take on faith. A threat model is the written answer. The usual way into one is four questions: what are we working on, what can go wrong, what are we going to do about it, and did we do a good enough job. For an agent, the honest answer to the second question starts early and runs long, because much of what the system runs on cannot be trusted at all.

The pages in this module use a few words in fixed senses. An agent is a program that calls a language model in a loop, running the tools it requests. The controller is the program that starts the agent, holds the credentials, runs the checks and decides what happens next: the model proposes; the controller acts. A check is a test, evaluation or policy rule whose result gates progress. Evidence is something the controller observed itself, and a claim is something the agent said. The sandbox is the contained environment the agent's commands run in, and an approval is a person's decision that lets one specific thing proceed.

With those words the threat model has a simple shape. There are three things you do not trust. The model's output, whether it is a command, a file path or a patch, is a proposal. Everything the agent reads, from a tool result to a file in your own repository, may carry instructions. And the agent's account of what it did, that the tests pass or the work is finished, is a claim. Prompt injection, and why it may never be fully mitigated, is a subject of its own under failure modes. This concept turns it, together with the other two, into a written list of who and what you trust and where the line between them runs.

Coding agents are the running example, because the incidents told here come from a system that drives coding agents under a controller. Most of the principles hold for any agent that calls tools, and each page says where they do not.

What you are protecting, and from whom

Start with the assets, because they decide what a failure costs. For an agent that works on software there are four. The code, meaning the repository and everything that will run from it. The credentials, each of which is live authority to act. Production, the running system with its data and its users. And the record of what happened: the logs, the decisions and the state that says what is finished. The last one is the easiest to leave off the list, and an agent that can rewrite the record can make every other failure invisible.

Then the parties. The model is neither friend nor enemy; it produces the most plausible continuation of the text in front of it, whoever wrote that text. The controller is your code. The people are the owner who sets the work and whoever approves it. And then there is anyone who can put text in front of the agent. NIST's 2025 taxonomy of attacks on AI systems splits them in two. In direct prompt injection the attacker is the system's own user, typing instructions through the ordinary interface to override the instructions the system was given. In indirect prompt injection a third party controls something the agent reads, a page, a document, a file, and never needs to touch the agent at all. A coding agent working on a task someone else filed has both kinds of party in front of it.

Write the result down as lists. One real system's threat model names as trusted the operating-system kernel, the system and user service managers, the administrator account, the controller with its small trusted helper processes, and the operator's own processes outside every sandbox. Untrusted: every process an agent starts and everything it produces (workspace files, results, transcripts, runtime files, network traffic), the project repository's committed content, because agents write it, and every other local user account. Out of scope, stated openly: a compromised administrator account or kernel, a compromised operator account, malware on the host, and what the model provider does with what it is sent.

The same document is plain about what its controls do not cover. A process running as the same user, outside every sandbox, can read the controller's token file, and could swap an agent's program between the moment it is hash-checked and the moment it is launched. Writing that down fixes nothing by itself. It tells you which assumptions the rest of the design must not lean on, and tells every reader what is still open.

The line runs around the controller

everything crossing in is checked; only the controller acts untrusted: the agent and everything it touches model output a proposal what it reads may carry instructions repository content agents wrote some of it its files and reports claims, hostile bytes proposes feeds in is read reports check check check check trusted: the controller and the people controller starts the agent, holds the credentials, runs the checks, decides what happens next people: the owner and whoever approves effects: only the controller acts code, credentials, production, the record what you are protecting the agent proposes, reads and reports; the controller checks and acts.
The model's output, what the agent reads, repository content and the files and reports the agent leaves all sit on the untrusted side; each crosses into the trusted side only through a check the controller runs, and the only arrow out to code, credentials, production and the record is the controller's own effect.

In threat modeling, a trust boundary is the line between zones with different levels of trust, and data crossing it is where checks belong. For an agent, draw that line around the controller and the people. Inside sit the code that holds the credentials, runs the checks and decides what happens next, and the people who approve. Outside sits everything the agent produces or reads: the model's output, tool results, the repository's content, and the files and reports the agent leaves behind. Notice that the agent itself is outside. The sandbox is where it runs, not a place where it becomes trusted.

Two rules follow from where the line sits. Whatever crosses inward is checked by the controller before it counts: a proposal is validated before anything acts on it, an input is handled as data, a claim is set against evidence. And whatever changes the assets goes out only through the controller: the commit, the merge, the deploy, the message. The agent can propose each of them; it performs none. One exception comes with hosted models: a provider's built-in tools run on the provider's servers, outside your controller. Under this boundary they are either switched off, or listed as something the agent can do on its own. The boundary works like a building's front desk, where every delivery is signed for and inspected before it goes upstairs, whoever it says it is from, and nothing leaves the building except through the desk. Nothing outside crosses by being labeled, wrapped in delimiters or summarized by another model, since all of those are more text; it crosses by passing a check.

Five working assumptions come straight from this picture. The agent's output is a proposal. Everything it reads may carry instructions. Its account of its own work is a claim. A file it wrote is hostile bytes until checked. And an earlier agent's output is untrusted input to a later one. Each is developed in its own concept in this module, under the controller's authority, evidence over claims, sandboxing and role separation.

The UK's National Cyber Security Centre gives advice of the same shape for any system built on a language model (2025): limit what the model can do with deterministic controls that do not depend on a model, and give a model that handles untrusted input no more power than the source of that input would have. A boundary drawn around the controller is that advice made concrete. The model can be talked round; the code at the boundary does not change its mind when the input is persuasive.

The attacker you did not write down

loopback keeps out other machines, not other websites the operator's machine a remote website anyone can run one serves a page operator's browser running that page request Host, Origin checked first if valid control panel 127.0.0.1 only wrong Host or Origin: refused another machine on the network connects refused: not loopback before the fix, with no Host check, the page's requests got past approve, spending and the emergency stop loopback is a network property, not an origin: check Host and Origin before anything else.
Listening only on the loopback address keeps other machines out, but a page from a remote website running in the operator's own browser sends its request from inside the machine, so the service has to check the Host and Origin of every request before it does anything.

A threat model earns its keep by naming the attackers you would not have imagined.

Field recordIn one real system, the agent controller had a web control panel that listened only on the loopback address, 127.0.0.1, and its designers treated that as the security boundary: nothing off the machine could reach it. A later audit found three gaps. Nothing checked the HTTP Host header. The protection against cross-site requests trusted a same-origin header. And a page reached through DNS rebinding could read the endpoint that handed out the panel's token. Together they gave a full bypass of approval, of spending (launching paid runs) and of the emergency stop, and with an optional benchmarking feature turned on, configuration writes and a 256 KB arbitrary file read as well. Twenty-six build stages had been adversarially reviewed by then. The record notes that nobody caught the missing Host check; as it puts it, "the threat model stopped at 'binds 127.0.0.1'."

The mechanism needs only a defender's level of detail. A page served from an attacker's domain keeps sending requests to that domain's name, and the attacker changes what the name resolves to, to 127.0.0.1. The operator's own browser then delivers the page's requests to the local service and still treats them as same-origin. What gives them away is that each request still names the attacker's host in its Host header, and a request that changes something also carries the page's origin. The Host check refuses all of them; the origin check is a second layer for the ones that act. Listening on loopback keeps out other machines. It does not keep out other websites, because the operator's browser is already inside, like a building that admits only its own staff, where any staff member will carry a stranger's sealed parcel up to any office, so the parcel arrives without the stranger ever passing the door.

Field recordThe fix checked Host first, then origin and token, and added a strict content security policy and caps on the size of a request body. The lesson recorded was to treat loopback as a network property, not as an origin. The system that replaced it started from that lesson: exact Host and Origin checks before routing or reading the body, no cross-origin resource sharing, a token on every change, compared in constant time, and the route that gives a browser its token switched off by default, because it "trusts request headers that a browser cannot forge and any other program can".

So list parties by what they can reach, not by where you assume they are. For an agent's controller that includes any website the operator visits, anyone who can file an issue or push a commit the agent will read, and any program running as the same user. Published security advisories describe the same rebinding attack against local servers that agents use as tools.

Its output is a proposal

What the model returns is text: a tool request, a shell command, a file path, a patch. None of it is an instruction your program is bound to carry out. It is a proposal, and the controller decides whether anything happens. The two places this goes wrong most directly are when proposed text reaches a shell, and when a path the model named is used exactly as given. OWASP's 2025 list of risks for language-model applications calls the general failure improper output handling: model output passed to another component without validation, which can open the way to cross-site scripting, privilege escalation or remote code execution.

Field recordIn one real system, an earlier, abandoned rewrite of an agent orchestrator was reviewed later, and the reviewer safely reproduced two defects in a scratch directory. The first was a path escape. The output writer accepted the path ../outside.txt and wrote a file above the project directory, because it resolved the path without checking that the result stayed inside. The second was shell expansion. In command-line mode the orchestrator pasted the prompt text into a shell command, escaping only double quotes, so a command-substitution expression in a prompt was expanded by the shell before it ever reached the agent program, which in the test was a fake. No real agent or model was involved.

These are path traversal and OS command injection, two old bug classes, arriving through a new door.

The review's conclusion was to keep the prototype's ideas and none of its code for running processes or writing files. Prompts and arguments reach every child process as data: an argument array or standard input, with no shell anywhere in the path, so characters such as ; and | stay characters. That alone is not enough, since a value can still be read as an option by the program receiving it, so any argument that could start with a dash is validated or placed after an end-of-options marker such as --. Every path an agent proposes is checked for containment, links and protected locations before anything writes to it.

The wider rule, that the controller rather than the agent performs every effect, belongs to the concept on the controller's authority. The narrower point here is the threat-model entry itself: nothing the model emits is executable, or a usable path, until a check says so.

Everything it reads may carry instructions

Why a model can follow instructions hidden in what it reads is a subject of its own under failure modes: instructions and data reach it through one channel, and no filter reliably separates them. For a threat model the useful work is the inventory. List every source of text the agent reads and treat each one as a party. For a coding agent that means the task text, the repository with its code, comments, documentation, test data and configuration files, the source of its dependencies, tool results, web pages, error messages and logs, and the text of issues. The repository is the one people forget. One real system's threat model lists the project repository's committed content as untrusted, because agents write it: yesterday's agent output is today's input.

The widest door is text from the public.

Field recordIn one real system, a design review looked at a loop in which reports from users of the live app were filed as issues automatically, and an agent that changes code then worked those issues automatically. The review flagged it as both a self-feeding loop and "a prompt-injection path". Anyone able to file a report could steer what code got written.

The design that came after it changes who can reach the agent, rather than trying to clean the text. Raw user reports are stored but kept out of every agent's briefing. The agent that watches production is read-only: it may read telemetry and file or update issues, and nothing else. An agent that implements a change sees a structured record, checked against a sanitized statement of how the product is meant to behave, rather than the user's words. And anything that touches a sensitive area, or falls outside the approved scope, waits for a person to decide.

That is the threat model doing its job. The report is still untrusted, and nothing has made it safe. What changed is that a stranger's sentence no longer arrives as an instruction to an agent that can write code; it arrives as a record whose fields the controller defined, and the decision to act on it belongs to someone inside the boundary.

Its account of its work is a claim

When an agent reports that it ran the tests and they passed, that it changed two files, or that the task is finished, it has told you something worth knowing and proved nothing. Its account comes from the same model as the rest of its output, with the same failure modes. It can be wrong honestly, it can stop early and report success on work that is only partly done, and it can be wrong because something the agent read told it what to say. A final answer is a claim that the work is finished, and written reasoning is not a record of what happened. Treat the report like a contractor's note saying the wiring is up to code: useful for knowing what they say they did, while the inspector still opens the wall.

The danger is in decisions that hang on the account. One real system's design names, as a failure to avoid, an agent's own declaration of what it changed being used to decide whether a person needs to look. Its rule is that whether a changed plan needs human approval is computed by the controller from the actual difference. The agent's declaration "can add uncertainty ... it can never suppress a detected change." Identity is handled the same way: which commits belong to the controller is read from the controller's own records, "never from a commit's trailers alone, which a role could write."

Claims you inherit get the same treatment. When the controller in that system takes over an existing codebase, its tests, CI results, badges, README claims and existing deployments count for nothing until they are proven. The adopted revision is pinned. Requirements an agent worked out by reading the code stay "unconfirmed" until the owner confirms each one. A table sets what the documentation says beside what is actually observed, existing tests count only as supporting evidence, and existing deployments are recorded as "unknown". The general rule reaches well past coding agents: an assertion you did not observe is a claim, whoever made it.

The working distinction is evidence versus claim. Evidence is what the controller observed itself: a test it ran, an exit status it read, a file it hashed. How to build verdicts from evidence alone, and why an empty pass is not a pass, is the subject of evidence over claims.

What one agent leaves, the next must check

between agents, the controller reads and rebuilds everything earlier agent writes a result result file controller 1. read only after the agent has stopped 2. no links followed, regular file, size cap 3. closed schema: unknown fields refused 4. references only to values on its own list 5. fields rebuilt by the controller itself rebuilt record later agent or the store any step fails whole result invalid, nothing stored
What an earlier agent leaves reaches a later agent or the store only through the controller, which reads the file after the agent has stopped without following links, parses it against a closed schema that refuses unknown fields and unlisted references, and rebuilds the fields itself; if any step fails the whole result is invalid and nothing is stored.

In a pipeline of agents, one agent's output becomes the next one's input, and the controller's as well. It is tempting to trust it because your own system produced it. But an instruction planted in what the first agent read can surface in what it writes, and the next agent receives that as input from a colleague. So the rule is that anything an agent wrote is untrusted data when the next agent or the controller reads it. One real system's design lists the failures this guards against: fields smuggled into a result, and an agent writing commit metadata that makes its commit look like the controller's or the owner's.

The mechanism is a closed shape. Plans, results and committed files are parsed against closed schemas, and unknown fields are refused rather than ignored. Any reference must be a value the controller itself enumerated: a finding must name a check from the controller's current list, or the whole result is invalid and nothing is stored. The controller rebuilds the fields of a result itself instead of passing the agent's version through, and a plan an agent writes is registered as data, not executed.

Files an agent wrote are hostile bytes too: a link, a named pipe or an endless device can stand where a result should be. The page on containing where an agent runs covers how to read them safely.

Both halves serve the same entry in the threat model, and separation of duties between agents takes the hand-off side further. The point here is that no output becomes trusted just because an agent on your side wrote it.

Some areas never get a lighter touch

A threat model also tells you where the damage would be worst, and some areas earn their checks however small a change looks. Risk labels are useful, since nobody wants a typo fix reviewed like a payment flow. But a label is itself a judgment, often made quickly and sometimes made by an agent, and a wrong "low" on the wrong part of the code turns straight into a skipped check.

One real system fixes a floor under the labels. These areas always get their required checks, at every risk level: authentication; authorization; payments and financial data; personal data; secrets and credential handling; data migrations and destructive operations on data; and irreversible actions in the outside world, such as sending messages on a user's behalf. Each area needs at least one required check that names it, at every gate.

Three rules keep the floor from wearing away. A module's own risk setting can raise its tier but never lower it. Delivering part of a requirement does not switch the floor off for the rest. And a low-risk label on the whole change does not reach the areas on the list. The same one-way pattern runs through the rest of this module: tightening is easy, loosening needs someone with the authority to loosen, and who that is, for checks and for approvals, is covered by protected checks and binding approvals.

The list is not specific to coding agents. Any agent that can touch login, money, personal records, secrets, stored data or the outside world is working in the places where one bad action costs the most, which is exactly where a threat model says the checks should be thickest.

One page, written first

The capstone this module builds toward is running a coding agent you do not have to trust. That phrase is a threat model in miniature. You decide in advance that the agent, everything it reads and everything it tells you are untrusted, and you build a controller that does not need any of them to be honest. So write the page before you write the controller: the assets, the parties, where the boundary runs, the five working assumptions, and the list of what is out of scope.

Every later control answers a line on that page. The controller performs the effects because the output is a proposal. The sandbox exists because every process the agent starts is untrusted. Credentials stay out of the agent's reach because they are an asset. Verdicts come from checks the controller ran because the agent's account is a claim. The checks are kept out of the agent's reach, approvals bind to exactly what a person saw, and the builder, the test writer and the reviewer run as separate roles, because the people and the record are assets too. Qualification makes sure the agent you run is the one you tested, stopping and undoing assume something will go wrong, and the tools you install are treated as text the agent will read. When someone proposes a new control, ask which line it answers. When someone proposes a new feature, ask which line it moves.

Be honest about what the page buys. These controls reduce risk; none of them makes an agent safe. The list records what is out of scope and what is still open, such as a same-user process that can read the controller's token. The UK's National Cyber Security Centre suggests a last question for any system built on a language model: whether the risk that remains is acceptable, and if it is not, whether a model belongs in that task at all. And the loopback story is the reminder to reread the page now and then. A threat model is only as good as its list of parties, and the one that matters is usually the one nobody wrote down.

Sources

The published studies, standards and guidance this page cites. Links open on other sites. Field records come from the author's own records and have no public source.

  1. Threat Modeling Cheat Sheet (OWASP Cheat Sheet Series) cheatsheetseries.owasp.org
  2. Adversarial Machine Learning: A Taxonomy and Terminology of Attacks and Mitigations, AI 100-2 E2025 (NIST, 2025) csrc.nist.gov
  3. Prompt injection is not SQL injection (it may be worse) (NCSC, 2025) www.ncsc.gov.uk
  4. DNS rebinding lets a web page find, exfiltrate, and delete private notes, GHSA-4gfv-c2mm-mvj2 (basic-memory, GitHub, 2026) github.com
  5. LLM05:2025 Improper Output Handling (OWASP Gen AI Security Project) genai.owasp.org

Next on your path to Run a coding agent you don't have to trust: