Control tool permissions
Allow or deny tool calls and use hooks to inspect the built-in agent loop.
Use permissions to decide which tool calls are allowed, and hooks to run your code at specific points in the built-in loop. Both are options of createHarness(). For commands that prepare a sandbox before a turn, use environment hooks instead.
Allow only what the task needs
Section titled “Allow only what the task needs”The model can read any file except .env files, edit under src/ and test/, and run npm test. Any other call returns Denied: <reason> to the model as a failed tool result, and the loop continues. Pass harness to createAgent({ harness, model }).
Write rules
Section titled “Write rules”Each rule has an effect ("allow" or "deny") and one or more conditions. A rule matches when all its conditions match.
API reference: HarnessPermissionRule.
The first matching rule decides. Without a match, default applies; it is "allow" when omitted. An allow rule with paths needs every path of the call to match; a deny rule needs only one.
paths and commands match only tools that declare them. The built-in file, edit and search tools declare their paths; shell and git declare their command. For your own tools, declare resources(input) (see Tools).
Intercept calls with hooks
Section titled “Intercept calls with hooks”Use hooks to add instructions at the start, refuse write_file calls after step 20 and ask for a test report before the agent finishes. Pass the exported list to createHarness({ hooks }).
Pass the list to createHarness({ hooks }). A hook that returns nothing leaves the loop unchanged.
API reference: HarnessHookPhase, HarnessHookEvents, HarnessHookDecisions and HarnessHookContext.
Order of checks and hooks
Section titled “Order of checks and hooks”Hooks of the same phase run in declaration order. For stop, the first hook that returns { continue } wins, and the extra step still counts toward limits.maxSteps.
Apply rules to subagents
Section titled “Apply rules to subagents”A subagent call runs only if the child’s permissions and those of every ancestor allow it, including after a hook rewrite. Hooks stay with the harness that declares them: parent hooks do not see the child’s calls.
Limits
Section titled “Limits”- Rules see only what a tool declares in
resources(input). A tool without it can be matched by name only. commands: ["npm test*"]also allowsnpm test; rm -rf src. List exact command lines.- Absolute paths and paths leaving the repository match no
pathspattern, so path deny rules do not catch them. The built-in tools refuse such paths; check them in your own tools. - Rules and hooks control which calls start, not what an allowed tool does:
npm testruns whatever the test script runs. Isolation comes from the sandbox; see Security.
API: defineHarnessPermissions · HarnessPermissionRule · defineHarnessHook · HarnessHookPhase · createHarness.