Sub topic 7
Limiting an Agent's Tools and Permissions
This chapter assumes you have read the chapters on custom agents and agent instructions. You should know that a custom agent is a Markdown or JSON file with a name, a role prompt, and a tool list. You should also be comfortable with basic YAML frontmatter.
Why scope tools
An agent can only do what its tools allow. A reviewer that has no write tool cannot edit your files, even if a confusing prompt tells it to. A rule in the prompt such as "never modify files" is a request. A missing tool is a hard limit. Use both, but rely on the limit.
Scoping also helps the model. A short tool list means fewer choices, less text in the context window, and fewer wrong calls.
Two layers of restriction
Most tools give you two layers. Names and syntax differ by product, so check your tool's documentation.
- Tool list: which tools the agent can see at all, such as read, search, write, or shell.
- Permission rules: which calls to an available tool run without asking, which need your approval, and which are denied. An example is allowing
git diffbut prompting for any other shell command.
The first layer decides what exists for the agent. The second decides what happens when it uses one.
Two examples
The reviewer from the earlier chapter lists only read-style tools:
---
name: code-reviewer
description: Reviews code changes for correctness, readability, and test coverage. Use after code has been modified.
tools: Read, Grep, Glob
---
You are a careful code reviewer. You only read code. Never modify files.The JSON form lists tools explicitly:
{
"name": "docs-writer",
"description": "Writes and updates project documentation",
"prompt": "You write concise technical documentation. Match the existing style in the docs folder.",
"tools": ["fs_read", "fs_write"]
}The docs writer can read and write files but has no shell tool. It cannot run commands, install packages, or call the network through a shell.
Choosing a tool set
Start from the task and grant the minimum that lets it finish.
| Agent role | Typical tools | Leave out |
|---|---|---|
| Code reviewer | Read, search | Write, shell |
| Documentation writer | Read, write | Shell, network |
| Test runner | Read, shell limited to the test command | General write access |
| Release helper | Read, write to one file, shell for Git | Network, other shells |
If an agent fails because it lacks a tool, add that one tool and test again. Widening later is easy. Finding out after an incident that an agent had too much access is not.
Review the decision flow
Common errors
- Granting everything "for now." Temporary access tends to stay.
- Relying on the prompt alone. The prompt can be overridden by text in a file the agent reads.
- Allowing a broad shell. A shell can do almost anything, including what you removed from other tools. Prefer narrow allow rules for specific commands.
- Not testing the limit. Ask the agent to do something it should not be able to do, and confirm that it fails.
Exercise
You are writing a custom agent that summarizes pull requests. It needs to read files and search the code. A teammate suggests adding a shell tool "in case it needs it." What do you do, and why?
Show answer
Leave the shell tool out. The agent's task needs only read and search tools, and a shell can do nearly anything, so it widens what a mistake or a malicious instruction in a file could cause. If testing shows a specific missing capability, add only that tool, or allow only the specific command it needs, and test again.