M31A does not use a single "is this allowed?" flag. A tool call passes through a stack of decisions, and a later layer can override an earlier one. This page describes the stack in the order it is applied.
The core implementation is in packages/core/src/policy/, especially policy-engine.ts, config.ts, and types.ts. The admission path from the agent is packages/core/src/scheduler/policy.ts.
1. Folder trust
Trust is the first gate. Until a folder is trusted, project context is not loaded and file and shell tools are restricted.
security.folderTrust.enableddefaults totrue.--skip-trusttrusts the folder for one invocation./permissions trustrecords trust interactively.M31A_TRUST_WORKSPACE=trueforces trust for non-interactive environments.
Trust state is stored locally. The policy engine also consults it while parsing shell commands: git commands in an untrusted folder are downgraded. See Sandboxing and trust.
2. Approval mode
The approval mode is the interactive baseline:
| Mode | Baseline |
|---|---|
default | Prompt before executing tools. |
auto_edit | Auto-approve edit tools; still prompt for other tools. |
plan | Read-only; writes and shell execution are blocked. |
yolo | Auto-approve everything (CLI flag only). |
general.defaultApprovalMode accepts default, auto_edit, and plan; YOLO must be requested per invocation with --yolo or --approval-mode yolo. security.disableYoloMode and admin.secureModeEnabled can block it. In policy TOML files the enum value is written autoEdit, matching the internal ApprovalMode type.
Mode selection filters rules: a rule with modes only applies in those modes. plan.toml contains a catch-all deny at priority 40, explicit read-only allows at 50, and narrow exceptions that permit writing plan files under .m31a/tmp/.../plans/.
3. Policy tiers and priorities
Policies are TOML files loaded from several directories. Each source is assigned a tier, and effective priority is tier + (priority / 1000):
| Tier | Source | Example priority |
|---|---|---|
| 1 | Default policies shipped in packages/core/src/policy/policies/ | 1.050 |
| 2 | Policies contributed by extensions | 2.100 |
| 3 | Workspace policies in <project>/.m31a/policies/ | 3.100 |
| 4 | User policies in the per-user .m31a/policies/ directory | 4.100 |
| 5 | System / administrator policies | 5.100 |
Higher numbers win. Within a tier, the file's own priority field breaks ties. Rules are sorted by descending effective priority, and the engine uses the first matching rule. This is why a workspace deny beats a built-in allow, and why an admin deny beats everything.
Extension policies are sanitized at load time: ALLOW decisions and rules targeting YOLO mode are discarded, so an extension cannot silently approve actions.
Useful built-in priorities:
| Priority | Meaning |
|---|---|
10 | Write tools require confirmation in interactive mode. |
15 | autoEdit overrides for edit tools. |
40 | Plan mode catch-all deny. |
50 | Read-only tools allowed; plan-mode read-only exceptions. |
70 | Mode-transition and plan-file write overrides. |
998 | YOLO allow-all. |
999 | ask_user stays interactive even in YOLO mode. |
4. Settings-derived rules
createPolicyEngineConfig() converts settings into policy rules in the user tier. This is why the settings reference calls these "deprecated" controls: they are still enforced, but as ordinary rules.
| Setting | Priority | Decision |
|---|---|---|
mcp.excluded | 4.9 | Deny (persistent server block). |
tools.exclude | 4.4 | Deny. |
tools.confirmationRequired | 4.35 | Ask user; overrides allowlists. |
tools.allowed | 4.3 | Allow, optionally narrowed by a command prefix. |
tools.core | 4.25 | Allow listed core tools plus a catch-all deny at 4.24. |
MCP servers with trust: true | 4.2 | Allow their tools. |
mcp.allowed | 4.1 | Allow listed servers. |
| Headless MCP auto-allow | 4.1 | Allow configured servers when mcp.autoAllowInHeadless is set. |
"Always allow" selections made in a confirmation dialog become dynamic rules at 3.95 for workspace scope or 4.95 for user scope. They are scoped to the current approval mode and more permissive modes, and security.disableAlwaysAllow or admin.secureModeEnabled can remove the choice.
5. Matching and shell analysis
A rule matches on tool name (including legacy aliases and virtual subagent names), optional mcpName, argument pattern, tool annotations such as readOnlyHint, approval mode, and interactivity. Argument patterns are compiled with SafeRegExp, a linear-time engine; native regular expressions are not accepted.
For shell tools, the engine parses the command and may split compound commands. Redirection and command substitution downgrade an ALLOW to ask_user unless the rule sets allowRedirection or allowCommandSubstitution. The YOLO default sets both.
There is also a hard build-file protection rule with maximum priority: editing a detected build configuration file is downgraded to ask_user (deny in non-interactive mode), regardless of a lower-priority allow rule.
6. Safety checkers
After a rule decision, safety checkers run unless the decision is already deny. Built-in checker types are:
allowed-path— path validation, used byautoEditrules inwrite.toml.plan-mode-command-guard— blocks mutating shell commands in Plan Mode.conseca— experimental context-aware checker, enabled bysecurity.enableConseca.
Checkers can deny or request confirmation. A checker that throws results in a deny, and in non-interactive mode any remaining ask_user becomes deny.
7. Administrator constraints
Admin controls are a distinct layer from ordinary rules:
adminPolicyPathsand the system policy directory form the highest tier.- If the system policy directory contains
.tomlfiles, supplemental--admin-policypaths are ignored; a central policy cannot be weakened by a command-line flag. - The system policy directory is skipped entirely if it fails a directory security check.
admin.secureModeEnabledblocks YOLO and "always allow".admin.mcpcan allowlist, blocklist, or require specific MCP servers.admin.extensionsandadmin.skillsrestrict those extension points.
Admin denial is final: no lower tier can restore permission.
8. Worked example
A workspace policy that blocks reading key material while allowing a specific safe shell prefix:
[[rule]]
toolName = "read_file"
argsPattern = ".*(\\.env|id_rsa).*"
decision = "deny"
priority = 200
denyMessage = "Secret files are blocked by workspace policy."
[[rule]]
toolName = "run_shell_command"
argsPattern = "^git status$"
decision = "allow"
priority = 100Load it for one run with:
m31a --policy ./company-policies.tomlThen inspect the effective rules inside the app with /policies list. Note that argsPattern values must be safe regular expressions; patterns that compile to an unsafe or catastrophic form are rejected.
9. Quick mental model
trusted folder? no -> restricted tools
approval mode -> baseline rules (plan is special)
rule tiers 1..5 -> highest priority match wins
settings allow/exclude -> ordinary user-tier rules
safety checkers -> can deny or force a prompt
non-interactive -> ask_user becomes deny
admin constraints -> cannot be overriddenNext steps
- Read Tool execution for where policy is checked.
- Read Approval modes and policies for the user-facing controls.
- Harden an untrusted repository with Sandbox hardening.