Build your own coding agent · Chapter 11 of 20
Permissions and approval
By the end of this chapter every tool call Kaarigar makes goes through one rule that answers allow, ask or deny; the paths go through the jail, the commands through chapter 7's kinds, the tests and the vendored SDK are protected; a person is asked about the commands that are fine only sometimes, can say "yes for this session", and is never asked about something that must be refused anyway. Build it in your browser: a real editor and terminal, AI that explains, and tests that tell you when it works.
- Part: The loop that fixes
- 4 tasks
- Python
- In the all labs plan
The first 2 chapters of Build your own coding agent are free. This one comes with the all labs plan.
Why you need this
Chapter 7's block list says never: no network, no sudo, no pipe into a shell, no push, no install. It says nothing about the commands that are fine sometimes:
rm -rf .pytest_cacheclears a cache;rm tests/test_fare.pydeletes the evidence. Both are delete.pip install pytzmay be exactly right, after Jaya has read what the package is. Chapter 7 refused every install, so it could never happen.git commitsaves the work locally. Jaya is fine with that on her laptop; another team might want to look first.python -c "..."is unknown: no list says what it does.
And chapter 7 only looked at run_command. An edit_file on tests/test_fare.py went straight through: in chapter 8, with only the names of the failing tests, the model edited the test file and skipped two tests.
Claude Code, Codex and Cursor's agent mode all handle this the same way: a set of rules over every tool call, a short list that is always allowed, a short list that is always denied, and ask the person for the rest, with an option to stop asking about the same thing for the rest of the session.
What you build: 4 tasks
Each task has tests. You write the code in the lab's editor and press Check.
- Task 1
rules.py: allow, ask or deny
Write is_protected(root, path): True when the resolved path, relative to root, is tests, vendor or .git or inside one of them. Write decide(root, name, args) -> Rule (Rule is given), deny first: a path outside the repository (inside() from agent.py) is deny; edit_file or create_file on a protected path is deny; any tool but run_command is allow. For run_command: a network, privileged, shell or git-remote kind is deny; rm, sed or mv on a path in tests/ or vendor/ is deny; any install, delete, write, git or unknown kind is ask, with those kinds joined by ", " as the reason; else allow.
- Task 2
policy.py: ask a person
Write policy(ask, granted=None), which returns a before_tool hook: decide's deny and allow stand; for ask, allow without asking when every kind is in granted, else ask "Kaarigar wants to run: COMMAND (KINDS). Allow?"; "session" adds the kinds to granted and allows, "yes" allows, "no" denies with "a person said no to COMMAND".
Under if __name__ == "__main__":, run MD-110 with SYSTEM plus "Commit your work when you are done.", tools() and a person who says no to installs and yes to the rest, printing asked: QUESTION and said: ANSWER for each question; then ran or refused and each command, then MD-110: fixed, N commits.
- Task 3
session.py: ask once a session
With one granted set and a person who always answers "session" (counting questions), run MD-101 then MD-102 with SYSTEM plus "Commit your work when you are done.", tools() and policy(person, granted). After each, print ID: fixed, commands run: N, asked so far: Q; then granted: KINDS.
- Task 4 · interview question
Interview: deny_wins.py
Run MD-101 twice (fresh checkouts, SYSTEM plus "Commit your work when you are done.", tools()), with the given ask_first(person) and then your policy(person), where person always says yes and counts questions. Print ask_first: asked N, push ran: yes|no and yours: asked N, push ran: yes|no ("push ran" when a run_command with git push was allowed).
What you will learn
- Three answers: allow, ask, deny, and why deny is decided first.
- One rule over every tool call: paths, protected folders, commands.
- Asking a person from the loop, and what the model does with a no.
- Session grants: ask once, not ten times.
- Why deny must win, even over a person's yes.
More in The loop that fixes
Build "Permissions and approval" yourself
MeterDown, a Pune app for auto-rickshaw fares, has eleven open issues. You build Kaarigar, an agent that fixes them without breaking tests, running risky commands or touching files outside the repository. A real editor and terminal in your browser, AI that explains, and a Check that says when it works.
The first 2 chapters of Build your own coding agent are free. This one comes with the all labs plan.