Most teams adopt a coding agent the same way: someone installs it, it does something useful on day one, and by the end of the month it has a GitHub token, a shell on a laptop or CI runner, and read access to half the company's repositories. Nobody wrote down what could go wrong, because it never felt like a new system. It felt like a better autocomplete.
It is a new system. It reads text from many sources, decides what to do, and then runs code with whatever access it was given. This post is a threat model you can copy and adapt: what you are protecting, how untrusted input gets in, what an attacker wants, and which control belongs where.
Start with the assets
Write down what the agent can touch, not what you intend it to touch. For a typical coding agent the list looks like this:
- Source code, including private repositories the token can read even if the task only needed one.
- Credentials in reach: the agent's own API keys, the Git token, cloud credentials in environment variables,
~/.aws,~/.ssh,.envfiles, the CI runner's secrets. - The machine it runs on: your laptop, a shared CI runner, a dev server. Anything the process can write to, it can damage.
- Your network position: internal services the machine can reach that the internet cannot.
- Money: model tokens, compute, and any paid API the agent can call.
- Your name: commits, PR comments and messages go out as you or your bot account.
If the list makes you uncomfortable, good. That discomfort is the threat model doing its job.
How untrusted text gets in
The core problem is simple to state. A language model does not reliably separate instructions from data. Anything the agent reads can steer what it does next. OWASP lists this first in its Top 10 for LLM applications as prompt injection, and it is not solved by better prompts.
For a coding agent, the entry points are everywhere:
- Issue and PR descriptions, including comments from people outside your organization.
- README files, docs and code comments in dependencies the agent opens.
- Web pages the agent fetches while researching an error.
- Tool output: test logs, compiler errors, HTTP responses. If an attacker controls a server the agent calls, they control text the agent reads.
- Files in the repository itself, if anyone outside the core team can get a change merged.
Assume every one of these can contain instructions written for the agent, not for you.
What an attacker wants
Simon Willison describes the dangerous combination as the lethal trifecta: an agent with access to private data, exposure to untrusted content, and a way to communicate externally. If all three are present, an injected instruction can read something private and send it out. Coding agents usually have all three by default.
Concretely, the goals fall into four groups:
- Exfiltration. Read a secret or private code and send it somewhere: an HTTP request, a DNS lookup, a comment on a public issue, a commit to a public fork.
- Persistence. Leave something behind that runs later: a modified CI workflow, a Git hook, a new dependency, a cron entry on a long-lived machine.
- Damage. Delete files, force-push, drop a database the machine can reach.
- Abuse of resources. Mine, spam or burn through tokens and compute. OWASP calls the cost side "unbounded consumption".
There is also a non-malicious version of every item: the agent misreads the task and does the damage on its own. Your controls should not care which one it was.
Put each control at the layer that can actually enforce it
The mistake we see most often is trying to solve everything in the prompt. A system prompt that says "never read .env files" is a suggestion. Here is where each kind of control can actually hold.
Layer 1: what the code can reach (isolation)
Run the code the agent writes somewhere that does not have your assets in it. That means not your laptop and not a CI runner that holds deploy keys. A throwaway environment per run, with nothing mounted from your machine, removes most of the asset list in one move: no home directory, no SSH keys, no cloud credentials unless you put them there.
How strong the boundary needs to be depends on whose code it is. For code from a model that read untrusted text, treat it as untrusted code. A shared-kernel container is a weaker boundary than a virtual machine with its own kernel; our isolation comparison goes through the trade-offs.
Layer 2: where data can go (network)
Exfiltration needs a way out. If the run has no network, or only a short allowlist of hosts it needs, most exfiltration paths close. This is the single control that breaks the trifecta most cheaply, because you rarely need to cut the private data or the untrusted input to get the task done, but you often can cut arbitrary outbound access. We cover how to build an allowlist in designing an egress allowlist for agent sandboxes.
Layer 3: which secrets exist in the run at all
A secret that is not in the environment cannot leak from it. Give each run only the credentials its task needs, scoped as narrowly as the provider allows, and make them expire when the run ends. Be honest about the limit: code inside the run can read whatever credentials you hand it. Short lifetimes and narrow scopes limit what a leaked value is worth.
Layer 4: which actions need a person
Some actions are cheap to undo and some are not. Running tests is cheap. Merging to main, pushing to a release branch, changing CI configuration, or touching production data is not. Put a human approval in front of the second group, enforced outside the agent, so a confused or hijacked agent cannot approve itself.
Layer 5: what you can prove afterwards
When something goes wrong, you need to know what the agent read, what it ran and what it touched. That means an audit trail written by the platform, not by the agent, and ideally one that shows if entries were edited or removed. Our post on what an audit log for coding agents should record lists the fields.
Layer 6: limits on time and money
Every run should have a wall-clock limit, every command a timeout, and every project a spend ceiling. Loops are the most common failure mode for agents, and they are boring rather than malicious. See timeouts for agent sandboxes for how the clocks interact.
A worked example
Take an agent asked to fix a failing test. It opens the issue, which was filed by someone outside the company. Hidden in the issue text is an instruction: run a script that reads environment variables and posts them to a URL.
Walk it through the layers:
- If the agent runs on a developer laptop with full network, the script finds whatever is in the environment and sends it. Every layer failed.
- If it runs in a fresh isolated environment with no network, the script runs, finds nothing interesting, and the request fails. The run fails, a human looks at the log, and the issue gets flagged.
- If the run needed network for package installs and had an allowlist of the registry hosts only, the request to the attacker's URL is refused.
- If the run held a deploy token because someone wanted the agent to "just ship the fix", the network layer is now the only thing standing between the attacker and that token. That is why secrets come third and not last.
None of these steps required the model to resist the injection. That is the point. Assume it will not.
Where Sandscale fits
Sandscale covers several of these layers for the code your agent runs. Each run gets its own Firecracker microVM with its own kernel, and a sandbox reaches only what your organization's egress allowlist allows. Vault hands a run its secrets in memory as environment variables for as long as the run lasts, and keeps them out of prompts, logs and API answers. Human approvals and a hash-chained audit log come with every plan, and DLP checks prompts and MCP tool calls for credentials before they leave. The security page has the full list by plan.
It does not decide whether your agent's change is correct, and it does not stop an agent from doing something harmful with access you deliberately gave it. The threat model above is still yours to write. Start with the asset list, and be honest about it.
Originally published on the Sandscale blog.