Skip to content

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:

bash
git clone https://example.com/untrusted.git /tmp/untrusted-review
cd /tmp/untrusted-review
m31a --approval-mode plan

Plan 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 ​

json
{
  "security": {
    "folderTrust": {"enabled": true},
    "disableYoloMode": true,
    "disableAlwaysAllow": true,
    "enableConseca": false
  },
  "admin": {"secureModeEnabled": true}
}
  • security.folderTrust.enabled keeps the trust gate active.
  • security.disableYoloMode blocks --yolo and --approval-mode yolo.
  • security.disableAlwaysAllow removes "always allow" choices.
  • admin.secureModeEnabled enforces 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:

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:

bash
m31a --policy ./hardening.toml

4. Constrain tools and extensions ​

json
{
  "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.core restricts the built-in set and adds a catch-all deny at slightly lower priority.
  • mcp.excluded denies every MCP server; --allowed-mcp-server-names can narrow this further for one run.
  • Disabling skills and extensions removes executable content bundled with the repository.
  • security.toolSandboxing isolates individual tools rather than the whole process.
  • Environment redaction and advanced.ignoreLocalEnv keep secrets out of context.

5. Add process isolation ​

Container sandbox (macOS and Linux) ​

bash
export M31A_SANDBOX=docker      # or podman, or true for auto-detect

Build 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:

VariablePurpose
SANDBOX_MOUNTSExtra mounts.
SANDBOX_PORTSExposed ports.
SANDBOX_ENVExtra environment variables.
M31A_SANDBOX_PROXY_COMMANDProxy command listening on :::8877.

macOS Seatbelt ​

bash
export SEATBELT_PROFILE=restrictive-closed

Profiles 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:

bash
# 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.

  1. Review in plan mode with no trust and no extensions.
  2. If edits are needed, use a container sandbox and default mode.
  3. Allow specific tools with narrow command prefixes; avoid broad "always allow".
  4. Keep secrets in the host environment, out of settings and M31A.md.
  5. Run untrusted code only in a disposable clone or worktree.
  6. 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 ​

SymptomResolution
Too many confirmationsNarrow an allow rule by command prefix instead of switching to YOLO.
Needed tool is missingCheck tools.core and tools.exclude.
Network call deniedUse a proxied profile and an explicit proxy allowlist.
Sandbox not activeM31A_SANDBOX requires Docker/Podman; macOS auto-detects Seatbelt.
Rule not appliedCheck tier precedence with /policies list.

Next steps ​

Built with VitePress. Powered by NVIDIA NIM.