I spent a week trying to keep a coding agent out of one directory, and I lost that argument at every layer that lives inside the agent.

The markdown rule folded when I claimed the repo owner was making an exception. The deny rule covered git commit and not git -C. The flag that turns off the write tool turned into a one line python3 call. What held was not the agent's at all: a sandbox profile from macOS itself, which kept holding after the agent switched off its own containment.

You do not stop Claude Code from writing files with the agent's own configuration. Across eight measurements run on the same Mac between August 16 and August 21, 2026, every layer inside Claude Code was bypassed at least once: a ban written in CLAUDE.md still ended in a commit in 3 of 4 runs once the request claimed the owner was overriding the rule, a deny rule for git commit never matched the git -C spelling of the same operation, and a session started with --disallowedTools Write Edit still ended with the file created in 2 of 3 runs. One layer held in every run we gave it: a macOS sandbox-exec profile denying writes to the working directory kept Claude Code 2.1.238 out of that directory in 3 of 3 runs, including the runs where the agent set dangerouslyDisableSandbox: true on its own Bash call.