Skip to content

AI Security · 3 min read

Least Privilege for AI Agents: A Practical Security Guide

Scoped permissions, sandboxes, secrets, audit logs and approvals: how to give AI agents the access they need and nothing more.

By · · Updated

Glowing orb agent in front of a ring of keys with only one key lit and a locked approval gate

We would never give every employee unrestricted access to production systems. So why do we do it with AI agents?

As agents become able to read databases, call APIs, send emails, update records, deploy code and run workflows, permissions stop being a detail. They become part of the architecture.

Adding an agent is like adding a developer

I used to think adding an AI coding agent was mostly a productivity decision. I do not think that anymore.

The interesting question is not that AI can write code. We are past that. It is what the agent can access while writing it: the repository, environment variables, git history, internal documentation, dependencies, local files and cloud infrastructure.

Give an agent enough permissions and, from an engineering point of view, you have added another developer to the team. Except this developer moves at machine speed.

The problem is not AI autonomy. The problem is uncontrolled authority.

The principle: least privilege

Least privilege means a user, or an agent, gets the minimum access needed for the task, and nothing more. We already apply it in backend systems. It applies even more strongly to agents, because they decide on their own when and how to use the access they have.

  • If an agent only needs to read customer data, give it read access.
  • If it needs to update one specific resource, scope the permission to that resource.
  • If an action can delete data, move money, change permissions or affect production, put a human approval step in front of it.

An agent being capable of doing something does not mean it should automatically be allowed to.

A practical checklist

If I were putting an AI agent into a real production workflow, I would want all of these:

  1. Scoped permissions. Narrow, task-specific access instead of broad roles.
  2. Isolated or sandboxed environments. The agent works in a place where a mistake cannot reach production.
  3. Protected secrets. Keep credentials out of the agent's context. Use short-lived, scoped tokens where possible.
  4. Restricted network access. Allow only the hosts the task genuinely needs.
  5. Audit logs. Record every tool call, every file read and every write, so you can reconstruct what happened.
  6. Approval for sensitive operations. Deletes, deploys, payments and permission changes need a human decision.
  7. Clear ownership. Someone is accountable for what the agent is allowed to do.

Authorization is architecture

Treat the agent like any other principal in your system. Give it its own identity, its own role and its own credentials. Do not let it borrow a developer's personal session.

In a multi-tenant product this matters even more. An agent acting for one customer must never be able to read another customer's data, which is the same isolation problem I describe in Django multi-tenancy: shared vs separate database.

The mistake to avoid

I think one of the biggest mistakes in the current AI rush will be giving powerful agents broad access first and thinking about governance later. The smarter the agent becomes, the tighter its boundaries should become.

I want AI to move fast. I just do not want a small mistake to turn into a production-wide incident.

So the more useful question about AI coding is not whether AI can write the code. It is what we are comfortable letting AI do on our behalf. That is where AI-assisted development stops being just a productivity feature and becomes an engineering problem.

Related: your own development machine is part of this attack surface too. See developer environment security.