How to give your AI agent only the access it needs
AI agent permissions for apps that serve many users: five boundaries, from whose account a call uses to what happens when access is withdrawn.
11 min read

An agent that works for one person can borrow that person’s access.
Most early agents do exactly that: one token, every scope it allows, and a model deciding what to do with it.
It works fine until the second user arrives.
An agent that serves many users can’t borrow anything.
Every call has to settle four things before it runs. Whose account is this, and which operation is allowed? Which records can it touch, and does a person need to approve it first?
OWASP calls the failure Excessive Agency, LLM06 in its 2025 list for LLM applications. It names three root causes: excessive functionality, excessive permissions and excessive autonomy.
This guide builds five boundaries against all three. Each section ends with a check to run against an existing agent. Where Agent200 documents the same rule, the section says so.
| Boundary | What it settles | Where to enforce it |
|---|---|---|
| User | Whose account a call uses | The authenticated request, never the model |
| Operation | Which tools the agent may call | The tool list and the executor |
| Record | Which items those tools can touch | The executor, before and after the provider call |
| Approval | Which actions wait for a person | A pause in the execution loop |
| Revocation | What happens when access is withdrawn | The connection store and the executor |
One rule governs all five: the model proposes, the executor decides.
1. Tie every call to one user’s connection
The shortcut is a shared token.
One admin connection, used for every user. It works in a demo.
It fails the first time two customers share an agent.
OWASP’s guidance is direct: actions taken for a user should run on downstream systems in the context of that specific user, with the minimum privileges necessary. In practice that means three rules:
- Give every user their own connection to each service. One OAuth application can serve many users. What has to be separate is each user’s authorized connection to it.
- Take the user’s identity from the authenticated request. Never from the model. A
user_idthe model can fill in as a tool argument is a user ID that a prompt can change. - Look up the connection at execution time, from that identity alone.
# Conceptual example
def call(self, user_id, tool, args):
"""user_id comes from the authenticated request. Never from `args`."""
conn = self.connections.get((user_id, "gmail"))
if conn is None:
raise NotConnected(user_id)
# ...refresh the token, run the tool, return the result
The model never chooses the account. That is the whole point.
If a tool call arrives with a user_id in its arguments, the executor ignores it. The arguments describe what to do. The request says who is asking.
Check: as user A, ask the agent for user B’s latest email, by name and by address. A passing agent returns nothing from B’s account, whatever the prompt says.
In Agent200: the Security page puts it plainly. “A request made for user_123 uses only the Slack and Gmail accounts that user_123 authorized.” In its SDK examples, the application names the user on the request, as agent200.user("user_123").run(…). Agent200 holds the connections “so your app never has to receive, store or rotate your users’ provider tokens itself,” and “Every user’s data is encrypted with individual keys.” Designing agents for many users goes through the setup.
2. Expose only the operations the job needs
Connectors expose far more than one agent needs.
An agent that summarizes unpaid invoices needs search and read. It doesn’t need send, forward or delete.
Every extra tool is a door. A manipulated model can walk through it.
Remove each one in two places:
- From the tool list, so the model never sees it.
- From the executor, so a call to it fails even if the model produces one anyway.
The second one is the real boundary. The executor is the only part of the system that can’t be talked into anything. A model can still emit a call to a tool it was never shown, whether from a hallucination, an injected instruction or a stale prompt. Only the executor is in a position to refuse it.
# Conceptual example
# Operation boundary, before anything else happens.
if tool not in self.allowed_tools:
raise PermissionDenied(tool)
Don’t let a tool decide for itself, either. The MCP specification lets a tool describe its own behavior through annotations. It also says clients must treat those annotations as untrusted unless they come from trusted servers.
Keep a separate record of what each tool does. Decide from that.
Check: call a disabled tool directly through the executor, bypassing the model. A passing setup rejects it before anything reaches the provider.
In Agent200: limits are set per project. The Security page says to “Choose which services and endpoints your agent may reach, per project and per workflow, down to the individual operation.” On the Gmail connector, a project can be limited to “messages and labels but not sending,” and single tools can be switched off. The Gmail page lists its read and write tools, and the email and calendar category shows the rest of the connectors, which makes the allowed set easy to decide up front.
A call then has to clear three layers: the project’s configuration, the user’s authorization and the provider’s own permission. In the Security page’s words, “A tool executes only when the necessary configuration, authorization and provider permission are all present.” Three layers of permission covers each one, and tool calling, from first principles shows where the executor sits in the loop.
3. Limit which records a tool can touch
Operation limits stop the wrong action. They don’t stop the right action on the wrong data.
OAuth scopes won’t solve this.
Google’s Gmail scopes cover the whole mailbox. gmail.readonly grants “View your email messages and settings,” and none of the scopes in Google’s list limits access to one label or one subset of messages. An agent meant to read invoices can read everything else too.
Record limits therefore live in the executor, in two parts:
- Constrain the request. Add the allowed scope to every query before it reaches the provider. Gmail’s
messages.listacceptslabelIdsand returns only messages carrying all of the listed labels. - Verify the response. Drop anything outside the allowed set before the model sees it. A message fetched by ID skips every search filter, so a fetch needs the same check.
The second part catches what the first misses.
The model controls the arguments. A model that has seen a message ID in one place can ask for it directly.
# Conceptual example
def _checked_message(self, user_id, message_id):
msg = self.provider.get_message(user_id, message_id)
if not self.allowed_labels & set(msg["labelIds"]):
raise OutOfScope(message_id) # never reaches the model
return msg
# Search is constrained first, then verified:
if tool == "gmail_search":
ids = self.provider.list_messages(user_id, sorted(self.allowed_labels))
return [m for m in ids if self._in_scope(user_id, m)]
Nothing outside the label reaches the model. Not even by accident.
Check: give the agent the ID of a message outside the allowed label and ask for a summary. A passing setup refuses, and the message body never reaches the model.
4. Make high-impact actions wait for a person
Some actions should never run on a model’s say-so. Sending to an outside address, deleting records, moving money, changing who has access.
OWASP’s guidance is to use human-in-the-loop control so a person approves high-impact actions before they are taken. The MCP specification says there should always be a human in the loop with the ability to deny tool invocations, and that applications should present confirmation prompts for operations. Both are recommendations, not requirements. Treat them as the floor.
An approval is more than a confirmation dialog.
It is a state in the execution loop:
- The executor sees a call to a gated operation and pauses it.
- A person sees exactly what will run: the tool, the arguments and the account.
- Approval runs that call, with those arguments, once.
- Denial ends that call. The agent must not reach the same outcome another way.
The fourth step is where most implementations leak.
A denied send followed by a draft and a send-draft is the same email by another route.
Gate outcomes, not only tool names. Decide which operations need approval from a list the team controls, not from what a tool says about itself. Then remember the denial for the rest of the task.
# Conceptual example
# gmail_send and gmail_send_draft share one outcome: "external_send"
outcome = self.outcome_of.get(tool)
if outcome:
if outcome in self.denied_outcomes:
raise ApprovalDenied(outcome) # denied once, denied for the task
if not self.ask_approval(user_id, tool, args):
self.denied_outcomes.add(outcome)
raise ApprovalDenied(outcome)
Check: trigger a gated action, deny it and watch the next few steps. A passing agent reports the denial and stops. A failing one finds another tool that gets the same result.
In Agent200: the approval step lives in your application. Giving your agent write access, safely covers the patterns: draft then confirm, and separate requests for reading and writing.
5. Treat withdrawn access as a hard stop
Users withdraw access, and tokens also stop working when nobody decided anything.
Google lists several reasons a refresh token can stop working, including a user revoking the app’s access, six months without use and a password change when the token carries Gmail scopes. Apps left in Testing status get refresh tokens that expire after 7 days.
An agent that treats every failed refresh the same way gets two things wrong. Some retry forever on a token that is gone. Others quietly fall back to another credential that still works. The second is the worst outcome: the call succeeds, on the wrong account.
The opposite mistake is just as real. A refresh can fail because the provider is having a bad minute. Marking the connection revoked on a timeout sends a user back through consent for no reason.
Sort the failures first:
| What comes back | What it means | What to do |
|---|---|---|
invalid_grant from the token endpoint |
The refresh token is invalid, expired or revoked. RFC 6749 defines it for an invalid, expired or revoked token. Google’s error_subtype can separate a revoked token from a session policy |
Mark the connection as needing reconnection. Stop the call. Tell the user which service to reconnect |
invalid_client |
The app’s own client credentials failed. This isn’t the user’s doing | Alert your team. Leave the user’s connection alone |
| Timeout, HTTP 5xx or a rate limit | The provider is struggling. It says nothing about authorization | Retry with backoff, a bounded number of times. Leave the connection as it is. If it keeps failing, tell the user to try again, not to reconnect |
Whatever the failure, one rule holds: never substitute another user’s credential, or an admin’s.
# Conceptual example
if conn.state == "needs_reconnect":
raise ReconnectRequired("gmail") # stop at the check, no provider call
try:
self.provider.refresh(user_id, "gmail")
except InvalidGrant:
conn.state = "needs_reconnect" # definitive: stop and tell the user
raise ReconnectRequired("gmail")
except ProviderUnavailable:
raise TransientProviderError("gmail") # not definitive: the caller retries with backoff
Once a connection is marked, later calls stop at the check. They don’t hit the provider again.
Disconnecting a user inside the product should revoke at the provider too. Deleting a row isn’t enough. RFC 7009 defines how a client does that, and Google documents its own token revocation.
The reconnect message deserves as much care as the check. OAuth connection prompts covers how to ask well.
Check: revoke the agent’s access from the provider’s own account settings, then run a normal request. A passing agent stops, names the service to reconnect and touches no other credential. Then simulate a provider outage on a healthy connection. A passing agent reports a temporary problem and leaves the connection marked as active.
In Agent200: authorization is one of the three layers every call needs, so a call without a valid user authorization doesn’t run. Agent200 runs the OAuth process for supported connectors, and the Security page notes “Tokens are refreshed where the provider supports it.”
Run all five checks
Each check fits in one test. Run them against a staging setup with two test users, kept apart from production. Agent200 keeps environments separate “so an experiment in development never runs with production access,” and environments for your agent covers the setup.
# Conceptual example: methods of a unittest.TestCase.
# build() creates test users A and B, a fake provider and an executor
def test_user_boundary(self):
executor, provider, _ = build()
# The model supplies a user_id in the arguments. The executor must ignore it.
result = executor.call("A", "gmail_get_message", {"id": "a1", "user_id": "B"})
self.assertEqual(result["body"], "Invoice 1041, unpaid")
self.assertEqual({user for user, _ in provider.accounts_used}, {"A"})
# Asking for B's message ID through A's connection finds nothing of B's.
with self.assertRaises(KeyError):
executor.call("A", "gmail_get_message", {"id": "b1"})
# A user who never connected gets a clear error, not someone else's account.
with self.assertRaises(NotConnected):
executor.call("C", "gmail_search", {})
def test_operation_boundary(self):
executor, provider, _ = build()
executor.allowed_tools.discard("gmail_send")
with self.assertRaises(PermissionDenied):
executor.call("A", "gmail_send", {"to": "finance@example.com"})
self.assertEqual(provider.accounts_used, []) # rejected before anything reached the provider
self.assertEqual(provider.sent, [])
def test_record_boundary(self):
executor, _, _ = build()
with self.assertRaises(OutOfScope):
executor.call("A", "gmail_get_message", {"id": "a2"}) # fetch by ID skips search filters
self.assertEqual(executor.call("A", "gmail_search", {}), ["a1"])
def test_approval_boundary(self):
executor, provider, asked = build(approve=False)
with self.assertRaises(ApprovalDenied):
executor.call("A", "gmail_send", {"to": "finance@example.com"})
# The same outcome through another tool is refused without asking again.
with self.assertRaises(ApprovalDenied):
executor.call("A", "gmail_send_draft", {"draft": "d1"})
self.assertEqual(provider.sent, [])
self.assertEqual(asked, ["gmail_send"])
def test_revocation_boundary_definitive(self):
executor, provider, _ = build()
provider.token_state[("A", "gmail")] = "revoked" # invalid_grant
with self.assertRaises(ReconnectRequired) as ctx:
executor.call("A", "gmail_search", {})
self.assertEqual(ctx.exception.service, "gmail") # names the service to reconnect
self.assertEqual(executor.connections[("A", "gmail")].state, "needs_reconnect")
calls_before = len(provider.accounts_used)
with self.assertRaises(ReconnectRequired): # later calls stop without retrying
executor.call("A", "gmail_search", {})
self.assertEqual(len(provider.accounts_used), calls_before)
self.assertEqual({user for user, _ in provider.accounts_used}, {"A"}) # no fallback credential
def test_revocation_boundary_transient(self):
executor, provider, _ = build()
provider.token_state[("A", "gmail")] = "down" # HTTP 503, not an authorization answer
with self.assertRaises(TransientProviderError):
executor.call("A", "gmail_search", {})
self.assertEqual(executor.connections[("A", "gmail")].state, "active") # not marked revoked
self.assertEqual({user for user, _ in provider.accounts_used}, {"A"}) # still no fallback
provider.token_state[("A", "gmail")] = "valid" # the provider recovers
self.assertEqual(executor.call("A", "gmail_search", {}), ["a1"])
Run them on every change to prompts, tools or connectors.
Permission bugs rarely announce themselves. They show up as a test that used to pass.
Least privilege for an agent comes down to one rule: the model proposes, the executor decides.
Put every boundary where the model can’t argue with it.


