Set runtime policies for commands and MCP tools
Runtime policies are enforcement rules for CLI commands and MCP tools, evaluated through coding-agent hooks. Each rule can stop a call, ask the person before it runs, or let it run while flagging it in logs and alerts.
CLI rules use the shell hooks in Claude Code, Cursor, Codex, GitHub Copilot CLI, and Pi. MCP tool rules are enforced in Claude Code, Cursor, and Codex. They do not apply to calls through the Willow gateway. For gateway enforcement, configure guards and MCP tool controls.
Before you start
- You need administrator access.
- Turn on Runtime Policy under Admin > Settings > Beta Features. Refresh the page if Policies does not appear in the sidebar.
- Enable guard hooks on the devices and coding agents you want to cover. On Policies > Runtime, Set up hooks opens their setup. A rule cannot enforce anything where the agent's hooks are off.
Runtime rules run alongside your guards. Guards keep their own scopes; creating a runtime rule does not change them.
Add a CLI command rule
-
Open Control > Policies and select Runtime.
-
Select Add rule, then CLI command.
-
Enter a Command: a program and up to two subcommand words. For example,
kubectlcovers all kubectl commands, whilekubectl deletecovers its delete subcommand. Flags and paths are not matched. Matching also works inside chained commands,sudo, andbash -c. -
Choose an Action:
Action Effect Block Stops the call before it runs. Ask user Asks the person to approve the call before it runs. Warn Lets the call run and flags it in logs and alerts. -
Under AI agents, select All agents to choose which coding agents the rule covers. Under Applies to, select Everyone to limit the rule to groups.
-
Optionally enter a Name, shown in logs and alerts, and a Message to the user explaining the decision.
-
Leave Rule is on enabled to enforce it, or turn it off to save it without enforcement. Select Add rule.
Add an MCP tool rule
Select Add rule > MCP tool, then enter:
- MCP server: the server to match, or
*for any server. - Tool: the tool name or a wildcard pattern such as
delete_*.
Choose the action, agents, groups, and optional message as above, then select Add rule.
Cursor does not report the MCP server separately. A server-specific rule there only matches tools whose name starts with that server name. Use the tool name reported by Cursor when configuring the match.
You can also open the rule editor with the gavel action on a command in CLI tools or an MCP tool in Tool calls.
Check enforcement
- Start with a rule limited to a test group and one coding agent.
- Let the Scan Agent sync the hooks, then restart the coding agent. See When devices get changes.
- Ask that coding agent to run a harmless command covered by your test rule, such as
git statusin a test repository. - Confirm the expected block, approval prompt, or warning, and inspect the matching event in Monitor > Logs. Warn lets the call run and records a warning.
- Check a command outside the rule's scope before expanding it to more people.
Troubleshooting
| Symptom | What to check |
|---|---|
| Policies is missing | Enable the Runtime Policy beta flag and refresh the dashboard. |
| The page says to set up agent hooks | Turn on hooks for a supported coding agent and let the device pick them up. |
| A CLI rule does not match | Use the program and up to two subcommands, without flags or paths. Check the rule's agent and group scope. |
| An MCP rule misses calls in Cursor | Check the reported tool name and the server-prefix limitation above. |
| A gateway call is unaffected | Runtime policies apply through coding-agent hooks. Configure gateway guards or tool controls for gateway calls. |