Sub topic 13
Approval gates and their limits
This chapter assumes you know the agent tool loop, indirect prompt injection, and the idea of least privilege from earlier chapters. You should also be able to read short Python and shell snippets.
What an approval gate is
An approval gate is a point where the agent stops and waits for a human to allow an action before it runs. Most coding agents ask before running a shell command, writing a file, or calling a network tool. Gates matter because an injected instruction can only cause harm if the agent acts on it. A person who reads the request can refuse it.
Where to place gates
Gate actions by how much damage they can do and whether you can undo them.
| Action | Reversible? | Suggested gate |
|---|---|---|
| Read a file in the workspace | Yes | Auto-allow |
| Edit a tracked file | Yes, through git | Auto-allow, review the diff later |
| Run an allowlisted test command | Yes | Auto-allow |
| Run an arbitrary shell command | No | Ask every time |
| Network request to a new host | No | Ask, or deny |
| Push, publish, or post a comment | No | Ask every time |
Gates work best on actions that send data out or change shared state. Gating every file read is not worth the cost, as the next section shows.
Why gates fail
Gates are a useful layer, but they have limits that you should plan for.
- Approval fatigue. After the fortieth prompt, people click "allow" without reading. An attacker benefits when safe and unsafe requests look alike.
- Blanket approvals. Choices such as "always allow this tool" turn a gate into a permanent hole. Injected text can then use that tool freely.
- Misleading descriptions. The prompt may show the agent's summary of an action, not the action itself. A command like
curlwith a long encoded argument is hard to judge. - Bundled actions. One approved script can do many things. Approving
make testalso approves whatever the Makefile contains, and an attacker may control that file. - Delayed effects. A harmless-looking edit now, such as a changed test script, becomes dangerous when a later approved command runs it.
- Automation. Agents in CI often have no human to ask. Chapter 16 covers this case.
Make the prompt reviewable
Show the exact argument list, not a summary. An allowlist, as in the earlier tool wrapper, lets you approve a small set of known commands once and refuse the rest by default.
import subprocess
AUTO_ALLOWED = {("git", "status"), ("git", "diff"), ("pytest", "-q")}
def run_with_gate(argv, ask):
if tuple(argv) not in AUTO_ALLOWED:
# Show the exact argument list, not a model-written summary.
if not ask(f"Run this command? {argv!r}"):
return "denied by user"
return subprocess.run(argv, capture_output=True, text=True, timeout=60, check=False)
def ask_on_terminal(message):
return input(message + " [y/N] ").strip().lower() == "y"
print(run_with_gate(["git", "status"], ask_on_terminal))The gate defaults to denial, because anything other than y returns a refusal. Calls on the allowlist skip the prompt, which keeps the number of prompts low and the remaining ones meaningful.
Practical guidance
- Allowlist common safe commands so prompts stay rare.
- Never grant "always allow" for shell or network tools.
- Require approval for any action that sends data out or changes shared state.
- Show the full command and its target, and log each decision.
Exercise
A teammate sets the agent to "always allow" for the shell tool because the prompts were annoying. Explain how a malicious issue could exploit this, and name one change that keeps the prompts manageable without this risk.
Show answer
With "always allow" on the shell tool, an injected instruction in an issue can make the agent run any command, such as one that sends environment variables to an attacker's server, and no human sees it first. A better approach is to allowlist specific safe commands like git status and pytest -q so they run without a prompt, and keep prompts for everything else. That cuts the number of prompts and keeps a human in front of the risky ones.