Topic 3 of 5 · 4 min read
Per-agent tools, credentials and scopes
Goal: Assign each agent in a system the minimum tools and credential scopes it needs and remove a shared broad credential.
Give every agent its own credential and the shortest tool list that lets it do its job, so that a compromised or fooled agent can only do what that one role was meant to do.
Check yourself · 1 of 3
Three agents (search, writer, publisher) all use one organisation-wide token. What is the main problem?
Why it matters
Many first multi-agent builds read one .env file: one API key, one database user, one set of tools handed to all agents. It is convenient. It also means the agent that reads random web pages holds the same power as the one that deploys code. If any single agent is fooled by an injected instruction, the attacker gets everything the shared key can do. Separate credentials also give you something else: logs that show which agent did what, and a way to revoke one agent without stopping the rest.
How to assign privileges
- List the agents and write each one's job in one sentence. "Searches public docs and returns citations."
- List what the job needs in terms of tools, data and actions. The search agent needs a search tool and nothing else.
- Choose the narrowest scope for each need. Read-only over read-write. One table over the database. One repository over the organisation. A path prefix over a whole bucket. A time-limited token over a permanent one.
- Issue one credential per agent, stored in a secret manager and injected at runtime, never placed in the prompt where the model can echo it.
- Remove the shared broad key. Rotate it, because it has already been seen by every agent and every log.
- Make the tool layer enforce it. The tool rejects calls outside the agent's scope; the agent's good behaviour is not part of the control.
- Log by agent identity and alert on a call outside the expected pattern.
Before and after
Before, one config for all three agents:
agents: [researcher, writer, publisher]
env:
GITHUB_TOKEN: ghp_...redacted # org-wide, repo:write
tools: [web_search, read_file, write_file, shell, git_push]
After:
researcher:
tools: [web_search]
credentials: none
writer:
tools: [read_file, write_file]
credentials: none
allowed_paths: ["drafts/"]
publisher:
tools: [git_push]
credentials: GITHUB_TOKEN_PUBLISHER # one repo, contents:write, expires in 1 hour
requires_approval: true
What goes wrong
- A tool list as wide as the biggest need. One agent needs shell once, so all get shell.
- Scopes named but not enforced. The prompt says "only touch drafts/" while the tool accepts any path.
- Keys in prompts. A model can repeat what it sees, including to another agent.
- Long-lived tokens. A leaked one-hour token is a smaller incident than a leaked permanent one.
Examples
Splitting a reviewer bot's token
A pull-request review agent uses a personal access token with repo scope, which can push and delete branches. It only needs to read the diff and post comments. Replace it with a GitHub App installation token limited to pull_requests: write and contents: read on one repository, and rotate the old token.
Path limits at the tool
def write_file(agent, path, text):
allowed = SCOPES[agent]["write_prefixes"]
if not any(Path(path).resolve().is_relative_to(p) for p in allowed):
raise PermissionError(f"{agent} may not write {path}")
...
The check resolves the path first, so drafts/../.env is rejected.
Key points
- One shared broad key means a fooled agent has the power of the strongest agent.
- Write each agent's job in one sentence, then give it only the tools, data and actions that sentence needs.
- Prefer read-only, single-resource, path-limited and short-lived credentials, injected at runtime and never put in a prompt.
- The tool layer must enforce the scope; a prompt that says to stay in one folder is not a control.
- Separate identities give per-agent logs and let you revoke one agent without stopping the others.
Common mistakes
- Sharing one API key or database user across all agents because it is simpler to configure.
- Describing limits in the prompt without enforcing them in the tool.
- Leaving the old broad key valid after splitting the credentials.
- Giving every agent the full tool list because one agent occasionally needs one tool.
Check yourself · 2 of 3
Which is the best credential for an agent that only posts review comments on one repository's pull requests?
Check yourself · 3 of 3
A prompt tells the writer agent to only edit files under drafts/, but the file tool accepts any path. What should you do?
Practice items, not counted towards your mastery.
Start here
- Design Patterns for Securing LLM Agents against Prompt Injections (arXiv) (opens in a new tab)PaperFree
Six named patterns, including plan-then-execute and dual LLM, with the utility each one gives up.
- Defeating Prompt Injections by Design (CaMeL, arXiv) (opens in a new tab)PaperFree
Shows a capability-based design that separates trusted plans from untrusted data and tracks where values flow.
- Agentic AI threats and mitigations (OWASP GenAI) (opens in a new tab)DocsFree
A threat catalogue for agents, including privilege compromise and multi-agent trust problems.
More for this topic
- The lethal trifecta for AI agents (Simon Willison) (opens in a new tab)ArticleFree
Private data, untrusted content and outbound communication in one agent is what makes theft possible.