Skip to main content

Designing Least-Privilege Access for AI Agents

How to build least privilege AI agents by deriving permissions from what they actually do

Updated 6 min readMarkdown
Part of seriesXccelera Blogs

Least privilege AI agents start from evidence, not guesswork. Run the agent on a real task in a sandbox and record every tool call.

Turn that trace into a draft allowlist, then compare it with what the agent was granted.

Anything granted but never used is a candidate for removal. Then repeat the review on a schedule so permissions stay tight as the agent changes.

This article walks through the full loop, including a short Python script you can run today. It replaces broad, inherited access with a policy built from observed behavior.

Why Do Least Privilege AI Agents Need Derived, Not Guessed, Permissions?

Most teams write an agent's permissions by hand, and they err on the side of "too much" so the demo works. OWASP's Top 10 for Agentic Applications names least agency as a foundation. Do not give an agent more autonomy than the task needs. The gap shows in practice.

A Cloud Security Alliance survey commissioned by Zenity found that 53% of organizations see agents exceed intended permissions occasionally or sometimes. Only 8% say it never happens.

Guessing fails because nobody knows in advance which calls an agent will make. Observation fixes that, and it gives least privilege AI agents a measurable starting point. For coding agents specifically, our repository access guide covers token scoping. This article covers the step before it: working out what to scope to.

least privilege AI agents permission workflow

What Should an Agent Access Control Design Include?

A sound agent access control design limits four things at once. Limiting only one leaves the others wide open.

Layer What to constrain Example rule
Tools Which tools the agent may call Allow repo:read, deny repo:merge
Data scope Which resources each tool touches One repository, not the whole organization
Credentials How long access lasts Short-lived tokens issued per task
Time When the policy is reviewed Re-derived every two weeks
agent access control design layers

The first row is where derivation helps most, because tool-level permissions are the easiest to over-grant and the easiest to measure.

How Do You Generate a Policy From an Agent's Trace?

Cloud teams already do this for human and service roles. IAM Access Analyzer reviews AWS CloudTrail logs. It then generates a policy template containing the permissions an entity actually used in a chosen date range.

The same idea works for least privilege AI agents. Log each tool call as one JSON line, then collapse the log into the set of tool and action pairs the agent used.

import json
import sys
from collections import Counter


def load(path):
    with open(path) as f:
        return [json.loads(line) for line in f if line.strip()]


def derive(trace, min_calls=1):
    seen = Counter((e["tool"], e["action"]) for e in trace)
    return {k for k, n in seen.items() if n >= min_calls}


def report(granted, used):
    for g in sorted(granted):
        print(f"{'KEEP' if g in used else 'TRIM':5} {g[0]}:{g[1]}")
    for u in sorted(used - granted):
        print(f"{'GAP':5} {u[0]}:{u[1]} (used, not granted)")


if __name__ == "__main__":
    trace = load(sys.argv[1])
    granted = {tuple(p.split(":")) for p in json.load(open(sys.argv[2]))}
    used = derive(trace)
    report(granted, used)
    draft = sorted(f"{t}:{a}" for t, a in used)
    json.dump(draft, open("draft_policy.json", "w"), indent=2)

Run it as python derive.py trace.jsonl granted.json. It prints a granted-versus-used report and writes draft_policy.json, the allowlist your trace supports.

Quick check: Your trace came from one happy-path task. Is the draft policy ready to ship?

No. One run shows what that task needed, not what the agent needs. Collect traces from several representative tasks first.

How Do You Read a Granted-vs-Used Report?

The report sorts every permission into one of three states. Each state has a default decision, so least privilege AI agents become a routine review instead of a debate.

Status Meaning Default decision
KEEP Granted and used Keep, and note the task that needs it
TRIM Granted, never used Remove unless a rare, documented task needs it
GAP Used, not granted Investigate first, because the call may be blocked or misconfigured

Treat TRIM as the main output. In the sample run, repo:merge and tickets:delete were granted but never used, which is exactly the kind of standing power an agent should not hold. Raise min_calls to ignore one-off calls that look like accidents rather than needs.

granted vs used permissions report for AI agents

How Do You Stop Permissions From Drifting Back?

Derivation is a snapshot, and least privilege AI agents still change over time. A new prompt, a new tool or a new workflow shifts what the agent calls. Use a ratchet.

Re-run the derivation on a fixed schedule and tighten the policy when the report shows TRIM items.

Loosen it only through a reviewed change with a named owner and a reason. Our guide to risk policies and kill switches covers the runtime side, so a bad call is stopped even when the allowlist is imperfect.

Quick check: An agent's policy was last derived three months ago, and the team has since added two tools. What should you do first?

Re-run the derivation against fresh traces before anything else, because the old policy cannot describe tools it never saw.

How Can You Review Agent Changes Before They Ship?

Permissions limit what an agent can touch. They do not prove that a change is safe. For least privilege AI agents that work on code, such as upgrading vulnerable dependencies, pair the allowlist with tested changes.

least privilege AI agents change review process

Add human approval and a recorded evidence trail. The policy keeps the blast radius small, and the review decides whether the change merges.

What Should Teams Take Away From This?

Least privilege for AI agents is easiest to hold when it is treated as a measurement rather than a design document.

Write down what the agent is allowed to do, record what it actually does, and let the difference drive the next change.

The teams that struggle are usually the ones that set permissions once, at launch, and never looked again.

Xccelera works on agentic software delivery. In that field agents act on real codebases, and an over-broad permission costs production incidents rather than test failures.

In that setting, the habit that matters most is not any single control but the loop: observe, compare, tighten, and review on a schedule.

A sensible first pass uses one agent, one week of traces and the script above. If the report shows a long TRIM list, that is the finding.

The permissions were broader than the work, and now you have the evidence to say so.

About the author

  • Xccelera AI is an enterprise agentic AI platform for building, orchestrating, integrating and scaling AI agents, from AI transformation strategy to production software engineering. Our platform and packaged agents (voice, ERP, ITSM, clinical assist, negotiation) come with human approval checkpoints, isolated execution and an audit-ready evidence trail for every run. Here we share engineering deep-dives on agent design, orchestration and observability. xccelera.ai
SSam4d ago

I like the shift from asking “what permissions might this agent need?” to “what permissions did it actually need across representative tasks?” That's a much better starting point for reducing over-permissioning. One important caveat, though: unused doesn't automatically mean unnecessary. Rare failure-recovery or escalation paths may never appear in a normal trace, so those need deliberate testing before permissions are removed. Least privilege should be evidence-driven, not blindly trace-driven.

Thanks, Sam. Agreed that unused doesn't automatically mean unnecessary. Recovery and escalation paths rarely show up in a normal trace, so they need deliberate testing before any permission is removed. Evidence-driven is the right frame, and the trace is only one piece of that evidence.

Granted-vs-used is a good way to make least privilege measurable. Two additions from agent security work: first, scope the credentials per run and make them short-lived, so a prompt-injected agent cannot reuse them outside the task. Second, derive the allowlist from traces that include adversarial inputs, such as a poisoned tool result or document, not only happy-path runs. Otherwise the policy is tight for normal behavior but says nothing about what an injected instruction could make the agent call. Logging the tool arguments, not just the tool names, helps here, because 'repo:read' on one repo is a very different grant from 'repo:read' on the whole organization.

Thanks, Osama. Both additions fill a real gap. A happy-path trace says nothing about what an injected instruction could make the agent call, so adversarial inputs belong in the data the allowlist is derived from. Short-lived per-run credentials and logging arguments, not only tool names, make the grant much more precise. repo:read on one repo versus the whole org is a good example of why.

The granted-vs-used report is a nice framing, but the weak spot is the trace itself. A permission that fires once a quarter, like a month-end export or a rollback tool, will show up as TRIM after a week of traces, and you only find out when the job breaks. We handle that with a small 'rare but documented' list that survives the ratchet, each with an owner and a review date. Your 'quick check' about one happy-path run being insufficient is exactly right. I'd add that min_calls=1 treats a single accidental call as a real need, so I'd pair it with a manual look at anything used exactly once.

Thanks for the detailed note. You're right that a permission used once a quarter will look like TRIM after a short trace window. A "rare but documented" list with an owner and a review date is a sensible way to keep those from being removed by mistake. On min_calls=1, a single call can't tell an accident from a real need, so pairing it with a manual look at anything used exactly once makes sense.