M31A policies are TOML files parsed by the core policy engine. The loader is packages/core/src/policy/toml-loader.ts; evaluation is in policy-engine.ts and config.ts.
File discovery
| Scope | Path |
|---|---|
| Built-in defaults | <core package>/policies/ |
| User | ~/.m31a/policies/ |
| Workspace | <project>/.m31a/policies/ |
| System/admin | macOS /Library/Application Support/M31A/policies, Windows C:\ProgramData\m31a\policies, Linux /etc/m31a/policies |
| Extension | <extension>/policies/ |
| UI "always allow" | auto-saved.toml in user or workspace policies directory |
A policy path may be a directory (only files ending in .toml are read, non-recursively) or a single .toml file. Missing paths contribute no rules. Additional paths come from policyPaths, adminPolicyPaths, --policy, and --admin-policy.
Minimal rule
[[rule]]
toolName = "glob"
decision = "allow"
priority = 100Rule fields
| Field | Type | Notes |
|---|---|---|
toolName | string or array | Required. * matches all tools; arrays expand into one rule per name. |
decision | string | Required. allow, deny, or ask_user. |
priority | integer | Required, 0..999; converted to tier + priority / 1000. |
subagent | string | Matches subagent identity. |
mcpName | string | Converts the rule to a fully-qualified MCP tool name. |
argsPattern | string | RE2-compatible regex matched against stable JSON of tool arguments. |
commandPrefix | string or array | Only with run_shell_command; mutually exclusive with argsPattern and commandRegex. |
commandRegex | string | Same restrictions as commandPrefix. |
modes | array | Optional filter: default, autoEdit, yolo, plan. |
interactive | boolean | true = interactive sessions only, false = non-interactive only. |
toolAnnotations | table | Every key/value must match the tool's annotations. |
allowRedirection | boolean | CamelCase wins; deprecated allow_redirection accepted. |
allowCommandSubstitution | boolean | CamelCase wins; deprecated form accepted. |
denyMessage | string | Message shown when the rule denies a call. |
Example rules
# Allow all read-only search tools in every mode.
[[rule]]
toolName = ["glob", "grep_search", "read_file", "list_directory"]
decision = "allow"
priority = 100
modes = ["default", "autoEdit", "plan"]
# Permit a narrowly scoped shell command.
[[rule]]
toolName = "run_shell_command"
commandPrefix = "git status"
decision = "allow"
priority = 220
# Block a destructive command pattern with a helpful message.
[[rule]]
toolName = "run_shell_command"
argsPattern = "(?s).*rm\\s+-rf.*"
decision = "deny"
priority = 300
denyMessage = "Destructive removal is blocked by workspace policy."Tier precedence
Rules are sorted by descending effective priority and the first matching rule wins. Priority bands encode scope strength:
| Tier | Scope |
|---|---|
1.x | Built-in defaults |
2.x | Extensions |
3.x | Workspace |
4.x | User |
5.x | Admin |
So admin rules outrank user rules, which outrank workspace, extension, and built-in rules. Generated rules occupy known slots: excluded MCP servers 4.9, --exclude-tools 4.4, confirmation-required 4.35, --allowed-tools 4.3, core tools 4.25, trusted MCP 4.2, allowed MCP 4.1, and "Always Allow" 3.95 (workspace band).
Match semantics
- Tool names match exactly, by wildcard, or through legacy aliases.
- For
invoke_agent, the subagent name is injected as a virtual alias so rules can target a specific agent. mcpNameidentity is checked strictly against server metadata.- No matching rule means
ask_userinteractively anddenynon-interactively. Inyolomode the default becomesallow. - Shell commands also pass redirection and command-substitution checks.
- Extensions cannot contribute
allowor YOLO rules.
Safety checkers
Policies may also define [[safety_checker]] entries with a [safety_checker.checker] sub-table:
type = "in-process"withnameofallowed-path,conseca, orplan-mode-command-guard,type = "external"with any command name,- optional
required_contextandconfig.
Sandbox policy
A separate schema in ~/.m31a/policies/sandbox.toml controls process sandbox behavior with [modes.plan|default|accepting_edits] sections (network, readonly, approvedTools, optional allowOverrides, yolo) and a [commands] table keyed by normalized command. The packaged fallback is sandbox-default.toml.
Inspecting and testing
m31a --policy ./policies --policy ./more-policiesIn-app, use /policies list to see effective rules. Start in a scratch workspace with a deny rule before deploying a policy broadly.
Next steps
See Policy evaluation, Approval modes, and Hook events.