Menu

Real access without the keys: a practical guide to AI agent security

11 min read

A practical guide to AI agent security: agents use the access, never the key. Smallest blast radius, Rule of Two, prompt injection, isolation.

How I let agents work on real GitHub, servers and databases without handing them a single secret, and what that still doesn't protect.

TL;DR: The model only produces text. The dangerous part is the harness that executes that text with your credentials. In practice AI agent security comes down to four rules: agents use the access but never see the key, every access gets the smallest blast radius that still does the job, no session gets untrusted input, sensitive access and the ability to act all at once (Meta's Rule of Two), and agents are isolated from each other. None of this makes prompt injection go away. It makes being fooled cheaper.


For about eight months I've been building infrastructure where agents work on real accounts: GitHub, servers, SQL databases, e-mail, websites behind a login. Not demos. Things where a mistake costs something.

Every rule below came from something that bothered me or broke. This post is the map; each part gets its own deep dive.

Three terms I use throughout, always in the same sense:

  • Agents use the access, never the key: the agent chooses the operation, the server injects the secret, and the result is redacted before the agent sees it.
  • Blast radius: how much one agent can break. The goal is the smallest scope that still lets it do its job.
  • Hope-based security: security that relies on a prompt, or on a second model acting as a judge.

Why isn't the LLM the dangerous part?

An LLM doesn't do anything. It produces text. That's it.

Remember when we copied code out of a chat window by hand? Then tools arrived and the model got hands. The harness (Claude Code, Cursor, Codex, OpenCode) reads the model's output, spots something that looks like a tool call, parses it and executes it. We stopped copy-pasting and started conducting.

But look at where the risk sits. The model on its own isn't dangerous. A harness that runs whatever the model came up with, without a second thought, is.

So the question isn't "how do I make the model behave". It's "what can the harness execute on the model's behalf, and with whose credentials?" That's architecture, not prompting.

What does your agent actually have access to?

More than you think. Give a coding agent bash and you don't give it "a tool". You give it you.

Every CLI you're logged into comes along: gh, aws, gcloud, az, vercel, supabase, plus whatever you logged into for a side project two years ago. And the agent can't only use those logins. It can print them. gh auth token shows your GitHub token in one command, no prompt. Nobody mentions this when you install a coding agent. Same with SSH keys sitting in ~/.ssh. The full walkthrough, with a 10-minute check of your own shell, is in a follow-up post.

Then there's .env. I don't know a clean way to protect it. If the agent can edit the app, and the app has to read the secrets, the agent can always make the app print them. More on that, and what to do instead, in a follow-up post.

Why don't permission prompts solve it?

Because they force a choice between two bad options. --dangerously-skip-permissions and peace of mind until the day it formats your disk. Or the leash: approvals every minute or two, three to five times less work done in my experience, and no overnight runs. And when an agent runs ten lines of bash, who actually reads them?

Auto mode, where a second model judges each risky action, beats hitting enter blindly. But the judge sees a slice of context. If the same agent wrote a nasty script two sessions ago and now only asks to run ./cleanup.sh, the judge sees an innocent one-liner. That's hope-based security: an attacker now has to fool two models instead of one. Rules have to live in code (hooks, policies, tools that validate before they execute). Details and a working hook in a follow-up post.

What does "agents use the access, never the key" look like in practice?

Take an API call. The agent decides the host, the endpoint, the body, and which stored secret goes where (it writes a placeholder, not a value). The server swaps in the real secret only at execution time. Whatever comes back is scanned, and any known secret values are redacted before the agent sees the response. And the host is checked against an allowlist for that connection, so the agent can't aim an authenticated request at a server that would simply collect the token.

The same idea works for CLI tools, SSH, SQL, e-mail and logging into websites. The agent gets the capability. The key stays home.

What does that buy you? A confused or poisoned agent can still misuse the access during that session, but it can't take the key with it. The secret isn't sitting in a transcript, a log or a model provider's context, waiting to leak later.

I'm not the only one doing this, and that's a good sign. OneCLI and Infisical Agent Vault, for example, also inject credentials so the agent never holds them.

How small should the blast radius be?

As small as the job allows. Security has to be architectural, and the most practical version of that is boring: granular access, narrowest scope.

An agent with a logged-in gh has your whole GitHub. My agents talk to GitHub through a Personal Access Token that can't delete a repository or create a new one. If one of them misbehaves, the worst case is a commit I revert, not a missing repo. With a fine-grained PAT that means picking only the repositories it works on and leaving Administration at "No access".

Scope it per agent, not per project: the agent running end-to-end tests needs a browser, the one writing docs doesn't.

Databases are where this hurts the most, and where the usual advice (a read-only user) is a decent floor but a workaround. That's a whole post of its own.

What is Meta's Agents Rule of Two?

Meta's Agents Rule of Two says that until we can reliably detect prompt injection, an agent should have at most two of these three in a session:

  • A: untrustworthy input (web pages, e-mails, files, MCP output, screenshots),
  • B: access to sensitive systems or private data (secrets count),
  • C: the ability to change state or communicate externally.

All three at once, and it shouldn't run on its own. A human approves. (Simon Willison's "lethal trifecta" is the same idea from a different angle.)

Now count a coding agent with bash on your laptop. Reads the internet: A. Every CLI you're logged into: B. Can push and curl: C. Three out of three, by default. 🙃

One subtlety I had to learn: hiding the key doesn't remove B. The agent still has the access, it just can't see the secret. "Agents use the access, never the key" fixes one specific failure, the key walking away. Rule of Two is about everything else the access can do.

So you drop one leg per session. A research agent reads the web but has no private data. An agent on your database takes input only from you, not from the internet. An agent that reads customer e-mails and your data can't send anything out without your sign-off.

Why is prompt injection risk number one?

Because it's the way in for everything above. The agent doesn't have to be "evil". It just has to read one poisoned README, e-mail or web page that turns "print the token and post it here" into part of the task. And I barely hear anyone worry about it. Most people seem to count on the models being smart enough, or on providers scanning upstream.

I built my own scanner for text, attachments and files. I can switch it on per agent so that all input coming in from APIs gets scanned. When it flags something, the item either lands in my inbox for approval or gets blocked outright. There's a dashboard with the incidents so I can see what got caught and how many were false positives. I built it earlier than planned, for an e-commerce project where agents were supposed to handle 100 to 400 customer e-mails a day. E-mail is the textbook definition of untrusted input.

Isn't a scanner just another judge, i.e. hope-based security? Fair question. Any detector, mine included, gets things wrong, which is why I track false positives. So it's not a boundary, it only lowers the risk. It's a smoke alarm that decides when to wake a human, which is the Rule of Two approval in practice. The boundaries are still scope, isolation and keys the agent never sees.

If you don't have a scanner, apply the rule by hand: an agent that reads e-mail or the open web doesn't get write access and secrets in the same session.

Why isolate agents from each other?

Because the blast radius of one poisoned agent shouldn't include every other agent.

My agents are isolated at the Linux level. Each has its own desk (a persistent workspace that survives sessions and restarts), and an agent can be set up so it has no access to any other agent at all. If it gets poisoned through prompt injection, the others don't even find out. A shared drive exists, but only agents that need it get it.

Without that, one poisoned agent running as the same user as everyone else can read the others' files, or quietly edit their notes so the next session reads them as truth.

It wasn't free: Landlock (Linux sandboxing) gave me 3 production bugs, and strict /tmp isolation had to be loosened again.

The cheap version for you: don't run all your agents as yourself. A separate OS user, container or VM per agent (or at least per trust level), with a clean home directory holding only the logins that agent needs.

What none of this protects you from

Most of what's above is a hard boundary, not risk reduction: a key that never reaches the agent can't leak from its context, a token without the right to delete a repo can't delete one, an isolated agent can't read its neighbour's files. But some setups can't be made 100% safe. Break the Rule of Two, or keep a .env file next to the agent, and the most you can do is reduce the risk. There the other option is a human in the loop: the agent stops and waits for your yes. That's the real trade-off with agents, autonomy or security. You don't pick it once. You set the dial per agent and per task: more autonomy where a mistake is cheap, an approval where it isn't.

  • Misuse of the access itself. Redaction stops the secret from leaving, not an agent with write access from writing garbage. Scope is the only defense.
  • Data leaking to allowed places. The allowlist protects tokens, not data. An agent that reads private data and may post to an allowed place (an issue, a chat channel) can still leak it. That's a Rule of Two problem.
  • Transformed secrets. Redaction matches values it knows. A secret deliberately printed base64-encoded or split in half is a harder case for any string matching. So redaction is a second layer that lowers the risk, not a guarantee. The first layer is that the secret never reaches the agent at all.
  • The model being fooled. Nothing here makes prompt injection impossible. It limits what a fooled agent can do.
  • An agent running as you, on your laptop. Then most of the above doesn't matter. It just reads the files. Isolation comes first.

And every safeguard broke something before it worked. Security and secrets are dozens of tickets in my history: a token that leaked into the model's context, an agent that could kill another agent's process or print a file with secrets. Some protections had to be loosened again.

Takeaway: the 7-point checklist

  1. Run gh auth status and the equivalent for every cloud CLI in the terminal you start your agent from. If it answers with your name, your agent can use it.
  2. Run the agent as someone else: separate OS user, devcontainer or VM, with only the logins this agent needs.
  3. Give it its own fine-grained PAT: selected repos only, Administration "No access", an expiry date.
  4. Database: never hand the agent your app's login. Either give it a SQL tool that enforces read-only on its own side, or create a separate database user that can only SELECT.
  5. No production secrets in a .env the agent works next to. Dev or dummy keys only.
  6. A PreToolUse hook as a hard block, fail closed. It's code, not a prompt.
  7. Check the Rule of Two for every agent that touches production or anything that really matters: untrusted input, sensitive access, the power to act. All three means it waits for your approval. Ideally you'd do this for every agent; realistically, start with the ones that can do damage.

What I built around this

All of the above is how I ended up building ARPOS, a place where agents work on persistent desks and use 8 types of access (CLI, API key, SSH, SQL, e-mail, web login, web session, Bitwarden) without ever seeing a secret. Secrets sit in an encrypted vault, tool calls are scanned and redacted, and the rules are enforced by the tools the agent has to go through, not by asking the model nicely.

It opens from December at arpos.ai.

FAQ

What is the biggest security risk with AI agents?

Prompt injection: a poisoned web page, e-mail or file makes the model treat an attacker's instructions as part of the task. You can't prompt your way out; you limit what a fooled agent can reach.

What does "agents use the access, never the key" mean?

The agent chooses the operation, the server injects the secret at execution time, and the output is redacted before the agent sees it. The credential never enters the agent's context.

What is the Agents Rule of Two?

Meta's rule that an agent should have at most two of three in one session: untrusted input, access to sensitive systems or data, and the ability to change state or communicate externally. With all three, a human approves.

Is Claude Code's auto mode enough to keep an agent safe?

No. It beats approving blindly, but a second model judging commands is still hope-based security. Put hard limits in code: hooks, narrow credentials, isolation.