Sub topic 1
What Least Privilege Means and Why Agents Need It
Prerequisites
This chapter assumes you know the following:
- How LLM tool calling (function calling) works at a basic level: the model returns a tool name and arguments, and your code runs the tool.
- What APIs and authentication tokens are.
- How to read short Python and JSON snippets.
- The idea of access control, such as roles and permissions.
The principle
The principle of least privilege says that a component should have only the access it needs to do its current job, and nothing more. A backup script that reads files does not need permission to delete them. A report generator does not need to send email.
The goal is to limit damage. Any component can be wrong, buggy, or tricked. If its permissions are small, the harm from a mistake is small too.
You can apply least privilege along four dimensions:
| Dimension | Question | Example |
|---|---|---|
| Functionality | Which operations can it call? | Only `search_docs`, not `send_email` |
| Scope | Which resources can it touch? | One folder, one S3 prefix |
| Duration | How long does the access last? | A token that expires in 15 minutes |
| Identity | Whose authority does it use? | The current user's, not a shared admin account |
Why agents raise the stakes
In ordinary software, a developer decides which action runs at each step. An agent is different. The model chooses which tool to call and which arguments to pass, based on text it reads. That text can include user requests, web pages, emails, and documents.
Two facts follow from this:
- The model's choices are not fully predictable. It can misread a request or pick a wrong argument.
- The model reads content from sources you do not control. An attacker can place instructions in that content. This is called prompt injection, and later chapters cover it in detail.
If the agent holds broad permissions, any of these failures can use all of them. An agent with an admin token and an email tool can be steered into sending private data to a stranger. An agent with only a read-only search tool can be steered into very little.
A worked example
Suppose you build a support agent that answers questions from a public report archive. A first draft might give it a general-purpose credential:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "s3:*",
"Resource": "*"
}
]
}This works, but it lets the agent read, overwrite, and delete every object in every bucket the account can reach. A single injected instruction in a report could cause real harm.
The task only needs to read public summaries. A least-privilege version looks like this:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::example-reports-bucket/public-summaries/*"
}
]
}The agent can now do its job. It cannot write, delete, list other buckets, or read private data. If the model is tricked, the worst case is that it reads files that were already public.
Where the limits must live
The limits have to be enforced by code and infrastructure, not by asking the model nicely. A prompt line such as "never delete anything" is a request, and injected text can override it. A policy that does not grant the delete permission cannot be overridden by any text.
Common mistakes
- Reusing a developer's or service's admin credential because it is already configured.
- Registering every available tool "in case it is useful."
- Granting access to a whole resource, such as a bucket or database, when one path or table is enough.
- Assuming a well-written prompt makes broad permissions safe.
The rest of this tutorial turns the principle into specific controls: tool allowlists, authorization in code, argument checks, scoped credentials, sandboxing, approvals, limits, and logs.
Exercise
An agent answers questions about a company wiki. It has a read_page tool, a delete_page tool, and a token with write access to the whole wiki. Name three changes that move it toward least privilege.
Show answer
Remove delete_page because answering questions never needs it. Replace the token with a read-only one. Limit the token and read_page to the wiki spaces the asking user may see, instead of the whole wiki. Enforce these limits in the tool code and credentials, not in the prompt.
Exercise
Why does least privilege matter more for an agent than for a traditional script that performs the same operations?
Show answer
In a script, the developer fixes which operations run and with which arguments. In an agent, the model chooses them from text that may include attacker-controlled content, so its actions are less predictable and can be steered. Narrow permissions cap the damage from a wrong or manipulated choice.