This tutorial sets up a defensive configuration for a repository you do not trust. It combines the layers described in Sandboxing and trust and Policy evaluation.
No single control is sufficient: trust decides what context is loaded, policies decide what calls are allowed, and a sandbox limits what a permitted call can reach.
1. Start with the smallest surface
Clone the repository into a disposable directory and begin in Plan Mode:
git clone https://example.com/untrusted.git /tmp/untrusted-review
cd /tmp/untrusted-review
m31a --approval-mode planPlan Mode denies writes and shell tools through the default policies, while read-only tools such as read_file, glob, and grep_search remain available. A plan-mode-command-guard safety checker is a backstop that rejects command separators, redirects, substitution, and known mutating binaries even if a future rule were to allow shell execution in Plan Mode.
Do not trust the folder permanently yet. Use --skip-trust only for the current session when you do need project context.
2. Keep trust explicit
{
"security": {
"folderTrust": {"enabled": true},
"disableYoloMode": true,
"disableAlwaysAllow": true,
"enableConseca": false
},
"admin": {"secureModeEnabled": true}
}security.folderTrust.enabledkeeps the trust gate active.security.disableYoloModeblocks--yoloand--approval-mode yolo.security.disableAlwaysAllowremoves "always allow" choices.admin.secureModeEnabledenforces both organization-wide.
In CI, M31A_TRUST_WORKSPACE=true is an explicit override; do not set it for interactive work with unfamiliar code.
3. Add deny rules
Create <project>/.m31a/policies/hardening.toml:
[[rule]]
toolName = "run_shell_command"
argsPattern = ".*(curl|wget|ssh|nc|bash -c).*"
decision = "deny"
priority = 500
denyMessage = "Network and interpreter commands are blocked in this repository."
[[rule]]
toolName = ["read_file", "grep_search", "glob"]
argsPattern = ".*(\\.env|id_rsa|\\.aws/credentials|gha-creds-.*\\.json).*"
decision = "deny"
priority = 500
denyMessage = "Credential files are out of scope."
[[safety_checker]]
toolName = ["write_file", "replace", "apply_patch"]
priority = 600
[safety_checker.checker]
type = "in-process"
name = "allowed-path"
required_context = ["environment"]Workspace rules sit at tier 3, so they override the built-in tier 1 rules. Use /policies list to confirm that they are loaded. Remember that argument patterns must be compiled as safe, linear-time regular expressions; do not use catastrophic backtracking constructs.
For a single invocation, you can also pass a file:
m31a --policy ./hardening.toml4. Constrain tools and extensions
{
"tools": {
"core": ["read_file", "glob", "grep_search", "list_directory"],
"exclude": ["google_web_search", "web_fetch"]
},
"mcp": {"allowed": [], "excluded": ["*"]},
"skills": {"enabled": false},
"extensions": {"disabled": ["*"]},
"security": {
"blockGitExtensions": true,
"allowedExtensions": [],
"toolSandboxing": true,
"environmentVariableRedaction": {
"enabled": true,
"blocked": ["NVIDIA_API_KEY", "AWS_SECRET_ACCESS_KEY"]
}
},
"advanced": {"ignoreLocalEnv": true}
}Effects:
tools.corerestricts the built-in set and adds a catch-all deny at slightly lower priority.mcp.excludeddenies every MCP server;--allowed-mcp-server-namescan narrow this further for one run.- Disabling skills and extensions removes executable content bundled with the repository.
security.toolSandboxingisolates individual tools rather than the whole process.- Environment redaction and
advanced.ignoreLocalEnvkeep secrets out of context.
5. Add process isolation
Container sandbox (macOS and Linux)
export M31A_SANDBOX=docker # or podman, or true for auto-detectBuild the image once from a checkout with npm run build:all. The default image is ghcr.io/eshanized/m31a-sandbox:0.2.0; override it with M31A_SANDBOX_IMAGE. The project directory and system temp directory are mounted read-write, and created files are mapped to your host user.
Additional controls:
| Variable | Purpose |
|---|---|
SANDBOX_MOUNTS | Extra mounts. |
SANDBOX_PORTS | Exposed ports. |
SANDBOX_ENV | Extra environment variables. |
M31A_SANDBOX_PROXY_COMMAND | Proxy command listening on :::8877. |
macOS Seatbelt
export SEATBELT_PROFILE=restrictive-closedProfiles come in permissive-*, restrictive-*, and strict-* groups, each with -open, -proxied, and closed variants. Built-in definitions live in packages/cli/src/utils/sandboxBuiltinProfiles.ts. For a custom profile create .m31a/sandbox-macos-<profile>.sb and set SEATBELT_PROFILE=<profile>.
Proxied networking
Set M31A_SANDBOX_PROXY_COMMAND to a command that starts a proxy on port 8877. M31A starts and stops it with the sandbox. Use a proxy you control to allowlist destinations; the -proxied Seatbelt profiles and container sandboxes both support this.
6. Verification checklist
Run this before accepting any change:
# Confirm the mode and effective rules inside the TUI:
# /policies list
# /tools list
# /mcp list
# Confirm nothing escaped the sandbox:
git status --short
git diff --stat
# Confirm the sandbox is active:
echo "$M31A_SANDBOX $SEATBELT_PROFILE"Then ask the agent to perform a safely blocked action, for example a network fetch or a write outside the project. It should receive a policy denial or a confirmation prompt, never silent success.
7. Recommended workflow
- Review in
planmode with no trust and no extensions. - If edits are needed, use a container sandbox and
defaultmode. - Allow specific tools with narrow command prefixes; avoid broad "always allow".
- Keep secrets in the host environment, out of settings and
M31A.md. - Run untrusted code only in a disposable clone or worktree.
- Remove temporary policies and trust entries when the review is done.
WARNING
Containers and Seatbelt reduce blast radius; they do not make malicious code safe. Hooks, MCP servers, and extension scripts execute with your privileges unless the sandbox confines them.
Troubleshooting
| Symptom | Resolution |
|---|---|
| Too many confirmations | Narrow an allow rule by command prefix instead of switching to YOLO. |
| Needed tool is missing | Check tools.core and tools.exclude. |
| Network call denied | Use a proxied profile and an explicit proxy allowlist. |
| Sandbox not active | M31A_SANDBOX requires Docker/Podman; macOS auto-detects Seatbelt. |
| Rule not applied | Check tier precedence with /policies list. |
Next steps
- Read Sandboxing for every variable and profile.
- Read Policy evaluation for precedence.
- Read Review a diff for a read-only workflow.