# Designing Least-Privilege Access for AI Agents

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](https://genai.owasp.org/2025/12/09/owasp-top-10-for-agentic-applications-the-benchmark-for-agentic-security-in-the-age-of-autonomous-ai/) 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](https://cloudsecurityalliance.org/artifacts/enterprise-ai-security-starts-with-ai-agents) 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](https://xccelera.hashnode.dev/ai-agent-access-control-code-repositories) covers token scoping. This article covers the step before it: working out what to scope to.

![least privilege AI agents permission workflow](https://cdn.hashnode.com/uploads/covers/693661c1dd06ab6f65c14cca/82a7ea18-d235-4988-90c0-fcaca3388a56.png align="center")

## What Should an Agent Access Control Design Include?

A sound [agent access control design](https://www.xccelera.ai/blogs/agentic-ai-governance-framework-template) 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](https://cdn.hashnode.com/uploads/covers/693661c1dd06ab6f65c14cca/1c60c8e4-7123-47e6-9519-2b612936a417.png align="center")

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](https://docs.aws.amazon.com/IAM/latest/UserGuide/access-analyzer-policy-generation.html) 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.

```python
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](https://cdn.hashnode.com/uploads/covers/693661c1dd06ab6f65c14cca/8e19b086-4311-497a-b1a7-bca9dbe8cd27.png align="center")

## 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](https://xccelera.hashnode.dev/detect-risky-ai-agent-actions-policies-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](https://www.xccelera.ai/guard) that work on code, such as upgrading vulnerable dependencies, pair the allowlist with tested changes.

![least privilege AI agents change review process](https://cdn.hashnode.com/uploads/covers/693661c1dd06ab6f65c14cca/c4cbf734-99ce-461c-822d-608bbb3d6f0f.png align="center")

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.
