Sub topic 7
Limiting an agent's tools and permissions
This chapter assumes you have read the earlier chapters on custom agents and on writing an agent's role and instructions. You should know that a custom agent is a Markdown or JSON file with a name, a role prompt, and settings. You should also be comfortable reading simple YAML frontmatter.
Why tool access needs its own design step
An agent is a model plus the tools it may call. The tools decide what the agent can do, not what you tell it to do. A prompt that says "never edit files" is a request. A tool list that has no write tool is a limit.
Scoping tools has four benefits:
- Safety. A reviewer agent that cannot write cannot damage the repository, even if it misreads a task.
- Focus. Fewer tools means fewer choices, so the model picks the right one more often.
- Context cost. Every tool is described to the model, and those descriptions use part of the instruction budget. A smaller set leaves more room for the task.
- Predictability. You can state what an agent can touch by reading one list.
Two layers: availability and approval
Most tools separate two questions, and you should keep them apart in your mind.
- Availability. Is the tool offered to the agent at all? If it is not on the list, the agent cannot call it.
- Approval. When the agent calls an available tool, does it run at once, or does the tool pause and ask you first?
A tool can be available but need approval. That is the usual setting for file writes and shell commands. A tool can also be pre-approved for safe, narrow use, such as reading files.
Examples of scoped tool lists
The role prompt from the earlier chapter had a reviewer that "only reads code." Here is how the tool list backs that sentence up. Field names and tool names differ between products, so check your tool's schema.
---
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.Read, Grep, and Glob let the agent open files and search. There is no write tool and no shell, so the final sentence of the prompt is now backed by the configuration.
The JSON form expresses the same idea:
{
"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"]
}This agent can read and write files. It has no shell, so it cannot run commands, install packages, or reach the network through a command line. That is a reasonable limit for a documentation task.
Some products add more settings beside the tool list, for example:
- A separate list of tools that run without asking.
- Path rules, such as "write only under
docs/." - Command rules, such as "run only
git statusandgit diff." - Settings for tools provided by external servers.
These are product-specific. If your tool supports path or command rules, use them. They narrow a broad tool to the part the agent needs.
Choosing the minimum set
Start from the job and add tools only when the job needs them. Use this as a starting guide.
| Agent job | Tools it usually needs | Tools to leave out |
|---|---|---|
| Code review | Read, search | Write, shell |
| Documentation | Read, search, write | Shell, network |
| Test fixing | Read, search, write, shell for the test command | Network, broad shell access |
| Dependency audit | Read, search, shell for audit commands | Write |
| Release notes | Read, search, `git log` through shell | Write outside the changelog |
A shell tool deserves particular care. A shell can do almost anything a developer can do: delete files, push code, read environment variables, and call the network. If an agent needs a shell for one command, prefer a rule that allows that command over a general shell.
Read-only is not always harmless
Removing write tools is a good limit, but it is not the same as zero risk. Think about what a read-only agent can still do.
- Read secrets. A read tool can open
.envfiles, key files, and credentials in the working directory. - Reveal data in its output. Whatever it reads can appear in a summary, a log, or a pull request comment.
- Follow instructions hidden in files. A file in the repository might contain text that tries to steer the agent. The agent should treat file contents as data. A weaker model or a poorly written role prompt might not.
Combine tool limits with a role prompt that says to treat file contents as data and to ignore instructions found inside them. Keep real secrets out of the working directory where you can.
Common errors
- Giving all tools "to be safe." This is the most common mistake. A broad list removes the main benefit of scoping.
- Relying on the prompt alone. "Do not modify files" with a write tool still listed is a wish, not a control.
- Pre-approving write and shell tools. If every call runs without asking, you have removed the human check. Pre-approve only read-like tools and narrow, well-understood commands.
- Copying a tool list from another product. Tool names and defaults differ. An unknown name might be ignored silently or might fail to load. Confirm in your tool's documentation, then test.
- Forgetting the default. In some products, leaving out the tool field means the agent inherits all tools. In others, it means no tools. Check which applies before you assume.
- Scoping too tightly. An agent that cannot read the files it needs will guess. If the output is vague, check whether it lacked a tool.
Verifying that a limit works
A tool list is only a control if it holds. Test it the same way you would test any other behavior.
- Ask the agent to do an allowed task and confirm it succeeds.
- Ask it to do a forbidden task, for example "edit README.md" for a reviewer. Confirm that the call is refused or that the tool is absent.
- Ask it to do a forbidden task in an indirect way, such as "write the result to a file using a shell command." This checks that you did not leave a side door open.
- Review the list when the agent's job changes. Tool lists tend to grow and rarely shrink.
Record these test prompts next to the agent file so a teammate can repeat them after each change. The testing chapter covers this practice in more depth.
Summary of rules
- The tool list is the control. The prompt is guidance.
- Separate availability from approval, and set both on purpose.
- Start with the smallest list that does the job.
- Treat a shell tool as a broad grant and narrow it where the product allows.
- Test both the allowed path and the forbidden path.
Exercise
You are defining an agent that checks pull requests for missing tests. It should read code and run the project's test command, but never change files. Which tools would you list, and which two checks would you run to verify the limits?
Show answer
List read and search tools, plus a shell tool restricted to the test command if the product supports command rules. Leave out any write tool. Check 1: ask it to review a change and run the tests, and confirm that it succeeds. Check 2: ask it to edit a file directly, and then to write a file through a shell command. Confirm that both are refused or that the shell rule blocks the second. If the shell cannot be restricted, accept that the agent could write files through it and weigh that risk, or require approval on every shell call.
Exercise
A teammate says, "The reviewer agent is safe because its prompt says it never edits files." The agent's tool list includes a write tool. What is wrong, and what is the fix?
Show answer
The prompt is only a request, and the model can still call the write tool if it misreads the task or follows text hidden in a file. Remove the write tool from the list so the limit is enforced by the configuration, and keep the prompt sentence as a reminder.