Least privilege for AI agents: credentials, tools and what an agent should never hold
An agent on a developer's laptop can use everything that developer can: the GitHub token in the keychain, the AWS profile, the kubeconfig, every .env file in the repo. Nobody granted it those permissions. It inherited them. Least privilege for agents starts with taking that inheritance back.
In short
- Agents inherit ambient credentials. Give each agent its own identity with only the access its job needs.
- Prefer short-lived, scoped tokens; keep production credentials off machines where agents run.
- Keep secrets out of the agent's reach, and hold any action that would show one to it.
- Least privilege can't stop an allowed action used wrongly. That needs a check on the action itself.
The problem: ambient credentials
In April 2026 a coding agent found an infrastructure token in a repository and used it to delete a startup's production volume and its backups in seconds. Nobody had given the agent that token; it was simply there. We wrote it up in 9 seconds: the PocketOS token.
That's the usual shape. Agents don't break in. They use what's lying around, with the same rights as the person who started them, and often with less judgement about when to stop.
Six practices for least-privilege agents
- One identity per agent, with an owner. Treat agents as non-human identities. Each gets its own credentials, tied to the person or team it acts for, so access can be scoped and revoked without touching anyone else.
- Short-lived, scoped tokens. Fine-grained GitHub tokens limited to the repos involved; cloud roles that are read-only by default; database users without
DROP. Expire them in hours, not months. - Keep production out of reach. No production credentials on machines where coding agents run. If an agent must touch production, it goes through a pipeline or a gateway that checks and records it.
- Keep secrets away from the agent. Deny reads of
.env, key files and credential stores in the agent's settings; load secrets at runtime from a secrets manager instead of files. - Fewer tools. Remove MCP servers nobody uses, allowlist the rest, and prefer read-only tools. Every tool is a permission.
- Separate dev and prod data. The Replit incident happened on a production database during a code freeze. An agent working on dev data can't delete prod.
Where least privilege stops
Least privilege shrinks what an agent can do. It can't judge whether a permitted action is right. An agent that's allowed to push will push to the wrong branch. One that can issue refunds can issue a hundred. One that can send email can send your data to an address a web page told it about.
Those need a check on the action itself, before it runs: what it is, what came before it, and whether a person should see it first. That's the action layer in our guardrails comparison.
How Squidbrake helps
- Secrets shown to the agent are held:
cat key.pem,gh auth token, reading credential files. So is sending a secret out. - Each agent key works for one person, so every action in the record says whose agent it was.
- Access levels for people too: owner, admin, approver and viewer; only
financeapproves wires if you say so. - Self-protection: an agent can't read Squidbrake's keys, approve its own action, or switch Squidbrake off without a person.
FAQ
What is least privilege for AI agents?
Giving each agent only the credentials, tools and data its task needs, for only as long as it needs them, instead of everything the person who started it can access.
Should AI agents have their own identity?
Yes. Treat each agent as a non-human identity with its own credentials and an owner, so you can scope, audit and revoke its access separately.
How do I keep secrets away from a coding agent?
Deny reads of .env files, key files and credential folders in the agent's settings, load secrets at runtime from a secrets manager, and hold any command that would print a token for a person to approve.
Is least privilege enough to secure AI agents?
No. It limits what an agent can do, but not whether a permitted action is the right one. Add a check on each risky action, such as a second person's approval, before it runs.
Try it on your own agents. pipx install squidbrake, then
squidbrake connect all. Start in shadow mode: nothing is blocked in week one, you see what would have been.
Quickstart · Benchmark · Book a demo