Least privilege for AI agents: scoping tools before you ship

$ cat blog/least-privilege-for-ai-agents.md
✓ AI security
✓ agents
✓ tool safety
✓ least privilege
9 min read
$ 

Least privilege is an old idea — give a component only the access it needs, nothing more — and it's the single most effective thing you can do for an LLM agent. Not because it stops prompt injection (nothing fully does), but because it decides how much a successful injection is *worth*. An over-privileged agent turns a bad paragraph of text into a bad action. A least-privileged one turns the same paragraph into nothing.

Privilege, for an agent, is its tools

For a traditional service, privilege means its credentials and network access. For an agent, it's all of that plus its tools — the shell, the file reader, the HTTP client, the MCP servers, the ability to open a PR. Each tool is a capability the model can invoke on text it may not fully control.

So scoping an agent means two questions, asked per tool:

  1. Does the agent need this tool at all? The cheapest tool to secure is the one you removed.
  2. Does it need the tool's full reach, or a slice of it? A file tool scoped to src/ is a different risk from one that can read /.
over-privileged shell: unrestricted read_file: / (whole disk) write_file: anywhere http: any host least privilege read_file: src/** only shell: (removed) write_file: (removed) http: (no egress)
The same agent, the same injection. Over-privileged on the left, scoped on the right. Least privilege doesn't block the attack — it removes what the attack would use.

The two columns are the same agent. The left one can be made to do real damage by a single injected instruction; the right one can't, because the capability simply isn't there. The injection is identical — the privilege is not.

Concrete scoping moves

  • Drop unused tools. Audit the tool list against what the agent actually does. Idle tools are pure attack surface with no upside.
  • Scope file access to a directory, and explicitly deny credential-bearing paths — .env, .git/config, key files, home-directory dotfiles. Assume any readable file is readable by an injection.
  • Make tools read-only where you can. A review agent reads; it rarely needs to write. Read-only is a hard ceiling on damage, not a speed bump.
  • Remove network egress from tools that don't need it. No egress means injected instructions can't exfiltrate, however clever they are.
  • Gate the writes that remain. Whatever write or destructive capability survives the cut should require human approval, not auto-run — the approval-gate pattern from prompt injection defenses that actually work.
  • Scope credentials to match. A tool with an admin token is privileged even if the tool itself looks narrow. Give it the smallest-scope credential that works.

The deny-list trap, again

It's tempting to keep a broad tool and "just block the dangerous stuff." It doesn't hold. Deny-lists enumerate the bad cases you thought of; injections find the one you didn't. Allow-lists enumerate the good cases, which are fewer and which you control.

deny-list:   allow everything EXCEPT rm, curl, wget, nc, ...
             → bypassed by the equivalent you forgot

allow-list:  deny everything EXCEPT read_file("src/**")
             → the attacker is limited to what you chose

Prefer deny-by-default with a small, explicit allow-list every time.

Why this is the highest-leverage control

Most agent-security advice — trust separation, output validation, input filtering — lowers the *probability* of a successful injection. Least privilege lowers the *impact*. Probability controls degrade as attackers adapt; an impact control doesn't care how the injection got in, because there's nothing on the other side to exploit.

Probability controls are an arms race. Impact controls are a ceiling. Build the ceiling first.

That's why least privilege is the floor the other defenses sit on, not an alternative to them.

How OpenRouting helps

OpenRouting inventories the tools and permissions in your agent setup during a scan and flags where privilege is broader than the task needs: unused tools, unscoped file or shell access, write-capable tools without approval, and credentials wider than their tool. The result is a short, specific list of "this is more powerful than it needs to be" — which is exactly the list least privilege asks you to work through. See how it works for where this fits in a scan.

Ship the narrow version. You can always widen a tool deliberately later; you can't un-leak what a wide one already reached.

Questions

What does least privilege mean for an AI agent?

For an agent, privilege is its credentials and network access plus its tools. Least privilege means giving it only the tools it needs, each scoped to the slice of reach the task requires.

How do I scope file access for an LLM agent?

Scope the file tool to a directory such as src/ and explicitly deny credential-bearing paths like .env, .git/config, key files and home-directory dotfiles. Make it read-only where you can.

Does least privilege prevent prompt injection?

No. It lowers the impact of an injection, not its probability: when the capability isn't there, injected text has nothing on the other side to use.

Why are allow-lists better than deny-lists for agent tools?

Deny-lists enumerate the bad cases you thought of, and injections find the one you didn't. Allow-lists enumerate the good cases, which are fewer and which you control.

Keep reading