Sharing API keys, passwords and other secrets with coding agents is an information security risk. I think it’s one of the stronger arguments against using LLMs for coding at all. Still, my experience has been that agentic software development can be very efficient, especially when the agents can interact with feedback loops. And without giving the agent the secrets and environment variables it needs, it feels like I’m handicapping that workflow. So I have spent a considerable amount of time thinking about how to share secrets with an agent while minimising the information security footprint. I would like to say safely, but there is no entirely safe way to work with a model that can reach the outside world.
Using agents in your main OS
I would imagine that anyone who has actively used LLM-assisted coding has shared secrets with the models. If an agent has, for example, used git on your behalf, it has likely had access to some sensitive data.
Most of us have run agents in our main OS, with plenty of things like SSH keys sitting around that a stupid or malicious agent could post somewhere. Usually this doesn’t happen, and the likelihood is very small. But because it isn’t zero, I would suggest that no one uses coding agents directly in their main system.
It’s nice that they can do everything you can do and use git on your behalf, but some people will get burned. It’s a bit like seatbelts. If you are running coding agents in your main OS, you are sitting in a car without one.
Potential security breaches
A secret can leak from two places: the agent’s context, meaning everything it has read or been told, and its environment, meaning every file and credential it can reach.
There’s a difference between an agent using a secret and an agent seeing it. When the agent runs git push, the secret never enters the conversation. When the agent reads a .env file, a command prints a key, or you paste one into the chat, the secret becomes part of the context.
While keeping secrets out of the context helps, it is not enough. Most attacks can get the agent to read a secret into the context without you noticing, or skip the agent entirely and read the files directly. The threat model is the same as for any developer’s machine: an agent can be tricked into running something bad, just like a person can. Some of the ways:
- Manipulating the agent: untrusted text tricks the agent into reading a secret and handing it over.
- Supply chain: the agent installs a package that ships your files somewhere.
- Code execution: something the agent installs or runs opens a reverse shell, which gives an attacker the same access the agent has.
- Intermediaries: a router or proxy between your agent and the model reads or rewrites the traffic.
- The tools: the agent’s CLI itself sends more than you expect.
- The model: the weights themselves have been tampered with.
- The vendor: logs at the model provider are kept, leaked or read by someone who shouldn’t read them.
Manipulating the agent
Agents read untrusted text all the time: web pages, issues, emails. This blog post shows an attacker impersonating Cloudflare to pass an identity check, and getting the agent to leak personal details that were never even given to it.
This is sometimes called the lethal trifecta: an agent that has access to private data, is exposed to untrusted content and can communicate externally can be tricked into stealing your data.1 A coding agent almost always has the last two. That leaves the first one, and making the private data worthless is what the rest of this post is about.
Supply chain
Agents install packages all the time, often without you looking. In March 2026, two releases of LiteLLM, a popular LLM proxy library, were published to PyPI with malware that collected SSH keys, cloud tokens and .env files.2
Code execution
If something the agent installs or runs gives an attacker code execution, the attacker doesn’t need the agent anymore. In July 2026, an npm package was found that contained nothing but a package.json, so scanners looking for code missed it. Its install script opened a reverse shell.3 The agent itself can be the way in, too. At Black Hat in August 2026, researchers showed that a single untrusted GitHub issue could get Claude Code to run attacker code, read arbitrary files and steal GitHub and Anthropic API credentials.4 Either way, the attacker gets the same access the agent has: every file, every environment variable and every credential on the machine. This is why it matters where the agent runs.
Intermediaries
Cheap or free LLM API routers sit between your agent and the model provider and see every prompt and response in plain text. A 2026 study tested 428 of them.5 Nine injected malicious code into responses, 17 touched AWS credentials the researchers had planted, and one drained ETH from a planted private key. One only started attacking after the first 50 calls, so a quick test would look clean.
The tools
In July 2026, xAI’s Grok Build CLI was found uploading entire tracked git repositories, history and tracked .env files included, to cloud storage.6
The model
The weights can be tampered with too. In a 2026 demonstration, a researcher fine-tuned a small open-weight model to quietly email confidential data to an address stored in its weights, while giving a perfectly normal answer.7 Earlier research showed that backdoors like this can survive standard safety training.8 These are research demonstrations with small models, but the point stands: you can’t read the weights to check them. You can only control what the model can reach.
The vendor
There is also the possibility of rogue employees at the LLM vendors who can access the logs. I wouldn’t trust claims that secrets are reliably sanitised from all outputs, or that logs aren’t kept at all. The industry is full of negligence.
What we can actually protect
You can’t audit every layer between your agent and the outside world. So I think it’s good to be slightly paranoid here, and to go through the small inconvenience of setting up a development environment that minimises the risk.
The secrets I mean here are mostly API keys and the like. Data itself, like trade secrets or the confidential data in the model example, is the same problem but much harder to protect. So let’s focus on the easier part: access keys and other credentials that open external systems.
Mental models that improve safety
Assume the leak
Assume the leak. Don’t just plan for it or write a policy about it: actually build on the assumption that everything the agent can see can be seen by someone else. Once that is the starting point, the interesting question stops being “how do I stop it leaking” and becomes “what can they read”. That is a much easier question, and unlike the first one, it has an answer you can engineer.
Make the secret worthless
The second move follows from the first: make the thing it can leak worthless to anyone else. A secret isn’t dangerous because it’s a secret. It’s dangerous because of how it can be used.
Local proxy
To make secrets worthless, or at least less dangerous, we can give the agent tokens that only work from inside a system you control, while keeping the real thing outside the box. The agent still gets its work done, because it can still ask for the operation. The secret just can’t be used outside your system.
That is the whole idea, and it looks roughly like this:
The sandbox is the “from where” and the expendable token is the “what it opens”. Neither half is much use alone. A sandbox with your real SSH keys in it is just a slower way to lose them, and an expendable token on your main machine is protecting the wrong thing. Together they mean the worst realistic outcome is that someone gets a credential that does nothing unless they are already sitting at my laptop, at which point I have considerably bigger problems.
I’m not saying remote code execution inside the sandbox isn’t a big deal. The sandbox can still call the main system for git operations, so if the token’s permissions allow deleting repos or doing other harm, you have a problem. The same goes for auto-approved tool calls: if the agent runs them without asking, an injected tool call is code execution inside the sandbox. But leaked keys alone don’t get an attacker anywhere. Sending the keys to an external address doesn’t give that address access, because all access has to be routed from inside the system. It might take the attacker a while to realise that, and in the meantime you’ll hopefully notice odd patterns in your logs.
What it looks like in practice
The goal is that every secret given to an LLM agent must be expendable. Right now I’m using this to limit access to GitHub and Postgres databases.
I run my setup with a tool called colimander, which I use to start a local Lima session with Colima. On the host OS I run a local proxy, so when my agent wants to talk to GitHub, it goes through host.lima.internal. The agent also runs on a separate file system. If my agent goes rogue, or pulls in a malicious NPM package that ships all my secrets somewhere, what the attacker gets is a local token that only works on my internal network, on my machine. It’s useless to anyone else unless they get full control of my laptop. And it should be quite hard to break out of the Lima VM. Hopefully, at least.
The same pattern in CI
I use the same pattern in other places as well, for example the CI runner in our internal git setup. The runner is an ephemeral machine that gets tokens for releases, migrations and so on, and all of those tokens are only usable inside the internal network. So if the runner is compromised, the credentials it leaks have a very limited blast radius and don’t work from anywhere else.
Typical software security ideology
None of this is new in software development. It’s the principle of least privilege: you grant your employees and users only the privileges they need to do their tasks. The LLM doesn’t need to talk directly to the external systems. It’s enough for it to talk to the local proxy. I suppose the novel part of my idea is applying this to local development.
The authors of the router study suggest similar defenses on the agent’s side, such as a policy gate that refuses anything it doesn’t recognise. A local proxy is one way to build that gate.
Conclusions
Coding agents are a lot more useful when they can reach real systems, and that means giving them credentials. I don’t think the answer is to stop doing that, or to trust that nothing will ever leak. The answer is to assume everything the agent sees can leak, and to make sure that what it sees is worthless anywhere else.
In practice that means two things: run the agent in a sandbox instead of your main OS, and give it only expendable tokens that work through a proxy you control. Neither idea is new. It’s least privilege, applied to your own laptop, and the setup is a small inconvenience compared to the alternative.
It’s not perfectly safe, because nothing that can reach the outside world is. But the worst realistic outcome drops from “someone has my GitHub and database credentials” to “someone has a token that only works on my laptop”.
Footnotes
- Simon Willison, “The lethal trifecta for AI agents: private data, untrusted content, and external communication”, June 2025. simonwillison.net ↩
- “LiteLLM PyPI Malware Steals Cloud, Crypto, Slack, and Discord Keys”, OX Security, March 2026. ox.security ↩
- “Malware detected: reverse shell without JavaScript files in npm”, OX Security, July 2026. ox.security ↩
- Ken Underhill, “Black Hat 2026: Critical Flaws Found in Anthropic, Google, and OpenAI Coding Agents”, eSecurity Planet, August 2026. esecurityplanet.com ↩
- Hanzhi Liu, Chaofan Shou, Hongbo Wen, Yanju Chen, Ryan Jingyang Fang & Yu Feng, “Your Agent Is Mine: Measuring Malicious Intermediary Attacks on the LLM Supply Chain”, arXiv:2604.08407, 2026. arxiv.org/abs/2604.08407 ↩
- “Grok Build uploads entire Git repositories”, The Hacker News, July 2026. thehackernews.com ↩
- David Kaplan, “The Mole in the Model: You’ve Hired an Adversary”, Origin, June 2026. originhq.com ↩
- Evan Hubinger et al., “Sleeper Agents: Training Deceptive LLMs that Persist Through Safety Training”, arXiv:2401.05566, 2024. arxiv.org/abs/2401.05566 ↩