An AI agent can do anything its tools and their credentials allow, whatever its instructions say, so least privilege for agents has to be built into the tools, tokens and policies rather than the prompt. Most agent incidents to date did not need a clever attack: an agent found or was handed a credential far broader than its task, and a model error or an injected instruction did the rest. This guide is the engineering method for scoping agent tool use: how to work out the minimum each task needs, which identity a tool should act as, how to narrow credentials at run time, and how to enforce limits at a decision point the model cannot talk its way past. It is written for platform engineers, identity teams and security architects who already know the agent tool threat landscape; for that background see the AI Agent Tool and Plugin Security Guide, and to record the result use the AI Agent Permission Matrix Template.
Key takeaways
- Instructions are not permissions. A code freeze written in a chat or a "never delete" line in a system prompt changes nothing about what a token can do; only the credential, the tool and the policy engine set the ceiling.
- Privilege sits in six places. Tool exposure, tool function, the identity a tool acts as, token scope, parameter and data limits, and approval gates each need their own minimum, and a gap in any one undoes the rest.
- Derive scopes from tasks, not from tools. Start from the actions a task needs, map each to an API permission, and only then decide which tools and scopes to grant; starting from "what the connector offers" grants everything it offers.
- Narrow at run time. OAuth token exchange, MCP progressive scopes, AWS session policies and Google Cloud Credential Access Boundaries all let a broad standing identity hand an agent a short-lived, narrower credential for one job.
- Measure granted against used. The working metric is the gap between the permissions an agent holds and the ones it exercised over 30 to 90 days; a large gap is unused blast radius.
Where tool privilege actually lives
Agent privilege is the product of several layers, and teams tend to secure the one they own. The table names each layer, who normally enforces it and what goes wrong when it is left at the default. Treat it as a budget: every layer should be set to the minimum, because the effective privilege of a tool call is roughly the weakest of them.
| Layer | Question it answers | Enforced by | Failure when left open |
|---|---|---|---|
| Tool exposure | Which tools can this agent see for this task? | Agent runtime, MCP client configuration, gateway | Every tool on every connected server is offered to the model |
| Tool function | What can one tool do? | Tool author | Open-ended tools (run_sql, shell, fetch any URL) that cover every action |
| Acting identity | Whose authority does the call carry? | Identity platform, tool server | A shared admin service account used for every user and task |
| Token scope and audience | Which APIs and operations will the token be accepted for? | Authorisation server, resource server | Omnibus scopes and tokens accepted by several services |
| Parameters and data | Which records, tenants, amounts and paths? | Tool server and backend | The tool trusts an account or tenant ID chosen by the model |
| Approval | Does a human confirm this action first? | Agent runtime or workflow engine | Destructive or external actions run without a gate |
OWASP's LLM06:2025 Excessive Agency describes the same problem in three parts, excessive functionality, excessive permissions and excessive autonomy, and its prevention list maps onto these layers: minimise extensions, minimise extension functionality, avoid open-ended extensions, minimise extension permissions, execute extensions in the user's context, require user approval and complete mediation. See the OWASP LLM06 Excessive Agency Guide for the risk itself.
Deriving the minimum: a scoping method
Least privilege fails most often at the design step, because nobody writes down what the agent is for. The method below produces a scope set you can defend at review.
- Write the task contract. One or two sentences per agent use case: the trigger, the outcome and the systems involved. "Summarise open invoices for the requesting user's cost centre" is scopeable; "help finance" is not.
- List the actions. Break each use case into verbs on objects: read invoice, list invoices by cost centre, create draft email. Mark each as read, write, delete, send externally or move money.
- Map actions to API permissions. For each action find the narrowest permission the target API offers (a read-only role, a single OAuth scope, one IAM action on one resource ARN). Record where the API forces a broader grant than the action needs; that is where a wrapper tool or a policy check has to make up the difference.
- Design the tools around the actions. Prefer purpose-built tools (get_invoices_for_cost_centre) to general ones (query_database). A narrow tool turns a policy question into a schema question, which is easier to enforce.
- Decide the acting identity and approval tier per action. Use the decision table in the next section, then assign each write, delete, external send or payment action an approval tier.
- Set the data limits. Say which tenant, records, amount ceilings and path roots apply, and where the backend enforces them from the authenticated identity rather than from tool arguments.
- Record it. Put the result in the permission matrix with an owner and a review date, so the scope has a source of truth that is not the agent's configuration file.
Choosing the identity a tool acts as
MITRE ATLAS splits agent access into three mitigations: AML.M0026 for agent service access, AML.M0027 for user-delegated agent access and AML.M0028 for access controls on agent tools. The ATLAS text for user-delegated agents is explicit that an agent acting for a user should not be granted permissions that the user would not be granted, and for shared tools it describes tools receiving the permissions, identity and restrictions of the agent calling them. The practical choice is between three patterns.
| Pattern | How it works | Choose it when | Main risk |
|---|---|---|---|
| Agent's own identity | The agent or tool server holds a workload identity with its own role | Unattended jobs with no human principal (nightly reconciliation, triage of a shared queue) | The role drifts upwards to cover every task the agent might ever run |
| Delegated user identity | The tool receives a token issued for the user, with consented scopes | Assistants acting for one person on that person's data | Agent inherits all of a privileged user's rights unless scopes are narrowed |
| Delegation with actor recorded | Token exchange produces a token that names both the user (subject) and the agent (actor) | Multi-step and multi-service agents where audit must show who acted for whom | More moving parts; resource servers must understand the actor claim |
RFC 8693 OAuth 2.0 Token Exchange distinguishes impersonation, where the actor is indistinguishable from the subject within the token's scope, from delegation, where the actor keeps its own identity and the token expresses both parties. In a JWT the act claim names the current actor, and nested act claims record earlier actors in the chain. For agents, delegation is the better default: it keeps the user's authority as the upper bound while letting logs and policy see that an agent made the call. The RFC also advises requesting only the access needed, notes that the authorisation server can reject requests for too many targets with invalid_target, and suggests the scope claim plus short token lifetimes to limit abuse of delegated rights. See the OAuth Token Exchange and Delegation Guide and AI Agent Service Accounts vs On-Behalf-Of Access.
Narrowing credentials at run time
The standing identity behind an agent is usually broader than any one task, because it serves many tasks. Run-time narrowing hands the agent a credential cut down to the current job and lets it expire. Four mechanisms are widely available.
OAuth token exchange
The agent's backend presents the user's token (subject_token) and optionally its own (actor_token) to the token endpoint with the grant type urn:ietf:params:oauth:grant-type:token-exchange, asking for a specific scope, resource or audience. The result is a token valid for one downstream service and a reduced scope. Never forward the user's original token to downstream APIs; the OAuth Token Exchange vs Token Passthrough guide covers why.
MCP progressive scopes
The MCP security best practices (specification revision 2025-11-25, checked November 2026) describe a progressive, least-privilege scope model: a minimal initial scope set containing only low-risk discovery and read operations, incremental elevation through targeted WWW-Authenticate scope="..." challenges when a privileged operation is first attempted, and servers that accept reduced-scope tokens. The same page lists common mistakes: publishing every scope in scopes_supported, wildcard or omnibus scopes such as *, all or full-access, bundling unrelated privileges to avoid future prompts, and treating scopes in a token as sufficient without server-side authorisation logic. It also states that MCP servers MUST NOT accept tokens that were not explicitly issued for the MCP server. See the MCP Authorisation Specification Guide.
Cloud credential narrowing
Platforms are listed alphabetically.
- Amazon Web Services: session policies are passed when creating a temporary session with
AssumeRole,AssumeRoleWithSAML,AssumeRoleWithWebIdentityorGetFederationToken, either one inline policy in thePolicyparameter or up to 10 managed policies inPolicyArns. AWS documents that session policies limit permissions for the session but do not grant them: the effective permissions are the intersection of the role's identity-based policies and the session policy, and a permissions boundary caps the role further. A broker can therefore assume one agent role per task with a session policy naming only the actions and resource ARNs that task needs. Note that a resource-based policy naming the session ARN as principal is not limited by the session policy. See the AWS IAM Permissions Boundaries Guide. - Google Cloud: Credential Access Boundaries downscope a short-lived credential for Cloud Storage. The documented flow is to define a boundary listing buckets and the maximum role per bucket (for example
inRole:roles/storage.objectViewer), create a short-lived credential, and exchange it for a downscoped token. A boundary holds up to 10 access boundary rules, one boundary applies per credential, and an optionalavailabilityConditionexpression can restrict access to objects under a name prefix, such as one customer's folder. Google documents this capability for Cloud Storage. See Google Cloud Agent Identity.
Where a target API offers no narrowing mechanism, put a broker tool in front of it that holds the broad credential and exposes only the needed operations, so the agent never sees the credential at all.
Enforcing limits outside the model
Every limit in the previous sections must be checked by code the model cannot rewrite. That means an explicit policy decision on each tool call, evaluated against the authenticated principal, the action, the resource and context such as the approval state.
- Policy decision point: a policy engine evaluated by the tool server or gateway. Cedar, for example, frames each request as principal, action, resource and context; its documentation states that by default the decision is Deny unless a permit policy grants the request, and that any satisfied forbid policy overrides a permit. Those two properties suit agents: unlisted tools fail closed, and a small set of forbid rules (no delete in production, no external send of restricted data) holds even when someone adds a broad permit later. Open Policy Agent is the other common choice; see Policy-as-Code for Authorisation.
- Bind resources to identity, not arguments: the tool derives tenant, user and record ownership from the validated token and rejects arguments that point elsewhere. A model-supplied
account_idis a request, not a fact. - Parameter ceilings: amount limits, recipient domain allowlists, path roots, row limits and rate limits per agent identity, enforced in the tool server.
- Environment separation: different identities and credentials for development, staging and production, so an agent working in staging physically cannot reach production.
- Complete mediation: check authorisation on every call, not once per session; OWASP LLM06 names complete mediation as a prevention step, and the MCP best practices require servers that implement authorisation to verify all inbound requests.
Approvals proportional to consequence
ATLAS AML.M0029 Human In-the-Loop for AI Agent Actions recommends that approval effort follow the degree of consequence: minor, repetitive tasks need little oversight, while high-consequence actions may need several approvers. Approval is the last layer, not a substitute for scoping, because people approve what they are shown.
| Tier | Example actions | Control |
|---|---|---|
| 0: autonomous | Read own records, search approved knowledge sources | Logged, rate limited |
| 1: notify | Create drafts, open tickets, write to a sandbox | Logged with user notification, reversible |
| 2: confirm | Send external email, change records, merge code | User confirms with the full parameters shown |
| 3: independent approval | Delete data, change access, payments, production changes | Approver other than the requester, outside the agent's channel, with step-up authentication |
See the Human-in-the-Loop for AI Agents Guide for approval design.
How to implement
- Inventory agents and credentials. List each agent, its tools, the identity each tool uses and every token or key reachable from its runtime, including files in the repositories it works in.
- Remove found credentials. Take long-lived tokens out of code and configuration that agents can read; issue credentials to tools through a broker instead.
- Write task contracts and the permission matrix for the highest-risk agents first: those with write, delete, payment or production reach.
- Introduce policy in log-only mode. Put the policy decision point in front of the tools, evaluate every call and log would-deny results for two to four weeks without blocking.
- Tune, then enforce by ring. Fix the legitimate denials, then enforce for one agent, then one team, then all. Keep forbid rules for production deletes enforced from day one.
- Switch to run-time narrowing. Replace standing broad tokens with exchanged, session-policy or downscoped credentials with lifetimes measured in minutes to hours.
- Roll back safely. Keep policy versions in source control so a bad change can be reverted in one step, and keep a documented break-glass path that grants a time-boxed wider scope with independent approval and full logging. See the AI Agent Kill Switch and Containment Guide.
Decision guidance
- Delegated versus agent identity: if a named person asked for the outcome and the data is theirs, delegate with the actor recorded; if no person is in the loop, use a dedicated agent identity per use case, never one per platform.
- Narrow tool versus policy on a broad tool: build a narrow tool when the action is frequent and stable; use a broad tool with parameter policy only when the action space is genuinely open, and then sandbox it.
- Small organisations: one agent role per use case, provider-native narrowing (session policies, downscoped tokens, minimal OAuth scopes), no standing production write access, and a weekly review of agent logs is a realistic baseline.
- Large organisations: a central token broker, a shared policy engine with forbid rules owned by security, agent identities in the identity governance process with recertification, and granted-versus-used reporting per agent. See Agent Identity Recertification.
Detection and measurement
Log every tool call with the agent identity, the delegating user, the tool, the parameters (redacted where sensitive), the policy decision and the scope of the credential used. Also log scope elevation events with the scope requested and the subset granted, as the MCP best practices recommend, and alert on denied calls, elevation loops and use of break-glass.
- Permission utilisation: permissions exercised divided by permissions granted per agent over 30 to 90 days; target a rising ratio.
- Standing credential count: long-lived tokens or keys reachable from agent runtimes; target zero for production.
- Policy coverage: share of tool calls that pass through a policy decision point; target 100% for write actions.
- Median credential lifetime issued to agents, trending down.
- Tier 3 actions without independent approval: target zero.
- Denied-call rate after enforcement, watched for spikes that suggest injection attempts or a broken task contract.
Common failure patterns
- Freeze by instruction: in the Replit AI Agent Database Deletion the code freeze existed only as a chat instruction while the agent kept write access to production.
- Found tokens: in the PocketOS Database Deletion an agent working in staging found an account-scoped token created for domain changes and used it to delete a production volume and its backups.
- Over-scoped automation tokens: the Amazon Q Developer Extension Compromise began with an over-scoped GitHub token, showing that the identities around agent tooling need the same scoping as the agent itself.
- Omnibus scopes requested up front to avoid consent prompts, so one stolen token reaches every tool.
- Trusting model-supplied identifiers for tenant or account, which turns any injection into cross-tenant access.
- Approval prompts that hide parameters, so users approve "send email" without seeing the recipient or attachment.
Framework mapping
| Framework | Reference | Relevance |
|---|---|---|
| NIST SP 800-53 Rev 5 | AC-6 Least Privilege; AC-6(9) Log Use of Privileged Functions; AC-6(10) Prohibit Non-privileged Users from Executing Privileged Functions | Minimum access per agent task; logging privileged tool calls |
| NIST SP 800-53 Rev 5 | AC-3 Access Enforcement; IA-9 Service Identification and Authentication; AU-12 Audit Record Generation | Policy decision on every call; identities for tool servers; call logging |
| NIST CSF 2.0 | PR.AA-05 | Permissions defined in policy, managed, enforced and reviewed with least privilege |
| MITRE ATLAS | AML.M0026, AML.M0027, AML.M0028, AML.M0029 | Agent service access, user-delegated access, tool access controls, human approval |
| MITRE ATLAS | AML.T0053 AI Agent Tool Invocation; AML.T0086 Exfiltration via AI Agent Tool Invocation | Techniques whose impact these controls limit |
| MITRE ATT&CK v20 | T1528 Steal Application Access Token; T1078.004 Cloud Accounts | Theft and reuse of agent tokens; short lifetimes and audience limits reduce impact |
| OWASP Top 10 for LLM Applications 2025 | LLM06:2025 Excessive Agency | Functionality, permissions and autonomy limits |
Practitioner checklist
- Write a task contract for every agent use case and derive scopes from its actions.
- Replace open-ended tools with purpose-built ones wherever the action set is stable.
- Use delegated tokens with the actor recorded for user-initiated work; never pass the user's original token downstream.
- Remove long-lived credentials from anything an agent can read, and issue short-lived, narrowed credentials through a broker.
- Request minimal initial scopes and elevate per operation; ban wildcard and omnibus scopes.
- Evaluate every tool call at a default-deny policy decision point with forbid rules for production deletes and restricted data.
- Derive tenant and record ownership from the authenticated identity, never from tool arguments.
- Separate development, staging and production credentials for agents.
- Assign an approval tier to every write, delete, send and payment action, with independent approval for tier 3.
- Report granted-versus-used permissions per agent and remove what is unused.
Standards and references
- IETF: RFC 8693 OAuth 2.0 Token Exchange
- Model Context Protocol: Security Best Practices
- OWASP Gen AI Security Project: LLM06:2025 Excessive Agency
- MITRE ATLAS: AI agent tool access mitigations
- NIST: SP 800-53 Rev 5 Security and Privacy Controls
- Amazon Web Services: Policies and permissions in IAM (session policies)
- Google Cloud: Downscope with Credential Access Boundaries
- Cedar: Authorization
Related NHI Mgmt Group resources: AI Agent Authorisation Guide · Agent Identity and Access Guide · Static Tool Allowlists vs Dynamic Tool Discovery for AI Agents · AI Agent Sandboxing and Code Execution Guide · NHI vs AI Agent Identity