motor / interlock

Clone with Amp

amp clone https://gauss.motor.dev/motor/interlock

interlock

interlock is a local Go CLI that decides whether a shell command is safe to run automatically or needs human approval.

It parses the command into a shell-agnostic IR (expanding variables, paths, symlinks, local scripts, and common obfuscations), scores it with an embedded 16.9M-parameter INT8 ModernBERT classifier (ettin-encoder-17m), and applies a deterministic policy engine with profiles and allow/deny rules. Everything ships inside a single static Go binary (~22 MB, CGO_ENABLED=0) and runs on CPU in ~8–16 ms per command (including cold startup).

Install

Prebuilt binary (macOS / Linux):

curl -fsSL https://gauss.motor.dev/motor/interlock/artifacts/install.sh | sh

Or with Go 1.26+:

go install gauss.motor.dev/motor/interlock@latest

Or from a local checkout:

./scripts/install.sh

Prebuilt static binaries (darwin-arm64, darwin-amd64, linux-amd64, linux-arm64, windows-amd64) are built by Piston on every landing to main and published under monotonic YYYY_MM_NNNN Gauss artifact versions (motor gauss artifact list motor/interlock), with a matching v0.YYYYMM.N Go module tag pushed automatically for go install ...@latest.

How it works

                   shell command + context
                              |
                              v
       +---------------------------------------------+
       |  1. Parse and expand                        |
       |     Resolve vars, paths, and obfuscation    |
       +----------------------+----------------------+
                              |
                              v
       +---------------------------------------------+
       |  2. Score risks (local ML model)            |
       |     Rate file, network, and system danger   |
       +----------------------+----------------------+
                              |
                              v
       +---------------------------------------------+
       |  3. Apply policy                            |
       |     Check profile, rules, and confidence    |
       +----------------------+----------------------+
                              |
                +-------------+-------------+
                |                           |
                v                           v
       +-----------------+         +-----------------+
       |      safe       |         |     blocked     |
       |   allow / run   |         | approve or deny |
       +-----------------+         +-----------------+

Usage

interlock check

Classifies a command and prints a JSON (or --format text) report. Exit codes:

  • 0: safe
  • 2: needs approval
  • 3: denied by explicit rule
  • 1: runtime error
interlock check --format text -- "rm -rf /etc/hosts"
interlock check --profile read-only -- "touch ./out.txt"
interlock check --rules .interlock.rules --audit-log session.jsonl -- "git push origin feat/ui"

interlock run

Takes the same flags as check. If the command is safe, runs it in the configured shell, directory, and environment and returns the child's exit code. If blocked, refuses to run, writes the report to stderr, and exits with 120 (needs approval) or 121 (denied) so blocked decisions do not collide with normal command exit codes.

interlock run --cwd /work/app --workspace /work/app --no-inherit-env --env PATH=/usr/bin:/bin -- "go test ./..."

interlock is a guardrail, not a sandbox. Static inspection and ML scoring catch common mistakes and hazards, but no classifier is perfect, and commands can still behave unexpectedly at runtime (for example, if a file changes or a script fetches new code). Pair interlock run with real isolation like containers, VMs, or scoped credentials whenever you run untrusted commands.

Passing explicit subagent context (--stdin-json)

When an agent runs commands in isolated subshells or worktrees, pass the context directly over stdin. Supplying "env" defaults inherit_env to false so ambient host variables do not leak in.

interlock check --stdin-json <<'EOF'
{
  "command": "./do_it $TARGET",
  "shell": "zsh",
  "cwd": "/work/subagent-1",
  "workspace": "/work/subagent-1",
  "home": "/home/agent",
  "user": "agent",
  "os": "linux",
  "env": {"TARGET": "/etc/hosts", "PATH": "/usr/bin:/bin"},
  "inherit_env": false
}
EOF

You can also pass context via flags: --shell, --cwd, --workspace, --home, --user, --os, repeatable --env KEY=VAL, --env-file <path>, --no-inherit-env, --fs-root <dir>, and --no-fs.

Other subcommands

interlock explain --format text -- "cd /etc && rm -f ./hosts"
interlock audit session.jsonl
interlock test-rules --rules .interlock.rules cases.json
interlock update           # self-update from Gauss artifacts (use --check to preview)
interlock version

What the frontend inspects

  • Shells: Bash, Zsh, POSIX sh, Fish, PowerShell, cmd.exe, plus a best-effort fallback tokenizer for other shells.
  • Expansion: cd/pushd threading (with subshell isolation), variable expansion ($VAR, ${VAR:-default}, %VAR%, $env:VAR), path canonicalization (~, .., symlink resolution, symlink-escape detection).
  • Local scripts & task runners: recursive inspection of ./script, sh/source (with positional arg binding, cycle/size limits), Makefile, package.json, justfile, Taskfile.yml, lightweight capability scanning for .py/.js/.rb/.pl scripts, and SHA-256 hashing of opaque local binaries.
  • Obfuscation & resource bombs: static decoding of Base64/Base32 (including file-backed base64 -D < file | sh), hex (xxd -r -p, \xHH), octal (\OOO), ANSI-C $'...', rev, ROT13 tr, quote/backslash splitting, and PowerShell -EncodedCommand; call-graph cycle detection for fork bombs (:(){ :|:& };:, renamed or mutually recursive functions, %0|%0, infinite background loops).
  • Audit log: --audit-log <path> (or INTERLOCK_AUDIT_LOG) appends locked JSONL entries (0600) with sensitive env values (*KEY*, *TOKEN*, *SECRET*, *PASS*, *AUTH*, etc.) redacted.

Profiles and rules

Built-in profiles (--profile):

Profile Auto-allowed Requires approval
read-only Read/inspect only All 16 risk labels
read-write fs_write_workspace, vcs_local_mutation Deletes, outside-workspace writes, network, packages, remote VCS, secrets, system/infra, opaque exec
read-write-delete (default) read-write + fs_destructive_workspace Everything outside workspace, network, packages, remote VCS, secrets, system/infra, opaque exec
remote-read-write-delete read-write-delete + network_download, package_or_env_mutation, vcs_remote_push vcs_destructive, outside-workspace FS, secret_access, network_egress, privilege/system/infra, opaque exec
full-access All commands Only explicit deny rules

Rules files (.interlock.rules) are evaluated post-expansion. deny always beats allow, and every sub-command and risk label in a compound command (A && B) must be allowed independently.

profile "read-write-delete"
confidence_threshold 0.85

allow cmd "git push origin feat/*"
allow cmd "go test ./..."
deny  cmd "rm -rf /**"

allow fs_write_outside_workspace, fs_destructive_outside on "/dangerous/**"
deny  secret_access on "**/.env*"
allow network_download where host "*.github.com"
allow opaque_or_dynamic_exec on "/work/repo/bin/codegen" sha256="<hex>"

Benchmarks

Metric definitions:

  • F1: harmonic mean of precision and recall (2 * precision * recall / (precision + recall), scored 0 to 1, higher is better). Precision is how often flagged commands are actually risky; recall is what fraction of real risks get caught. A high F1 requires both catching real risks and not crying wolf on safe commands.
  • Macro-F1: average F1 score across all 16 individual risk labels, weighted equally so rare labels count as much as common ones. Measures how accurately the model explains why a command is risky.
  • Any-Risk F1: binary F1 score on whether a command has any risk label vs. being completely safe.
  • Danger FNR (False Negative Rate): fraction of genuinely risky commands missed (0.0000 means none were missed; lower is safer).
  • Policy Benign FPR (False Positive Rate under read-write-delete): fraction of safe commands that unnecessarily asked for human approval (lower means less friction).
  • Latency: average per-command CPU time in milliseconds (pure Go, no GPU, no CGo). Embedded model loading takes ~0.3 ms (zero-copy binary weights and BPE table), so cold single-shot interlock check invocations typically report ~8–16 ms.

235-case held-out real-world & adversarial suite (eval_real)

Backend Macro-F1 Any-Risk F1 Danger FNR Latency
hybrid (default: ettin-17m INT8 + heuristic floor) 0.9891 0.9973 0.0000 (0/185 missed) 12.4 ms
neural (ettin-17m INT8 + frontend safety floor) 0.9868 0.9946 0.0054 (1/185 missed) 12.5 ms
baseline (deterministic heuristic) 0.9875 0.9946 0.0054 (1/185 missed) <0.1 ms

214-case blind unseen-tools OOD suite (eval_ood, zero overlap with datagen)

Tests tools and flags intentionally excluded from synthetic training templates (eza, dust, tokei, jj, hg, pulumi, fly, wrangler, rclone, http/xh, socat, ngrok, mongosh, redis-cli, duckdb, diskutil, fdisk, nsenter, vault, op, certutil, schtasks, etc.).

Backend Macro-F1 Any-Risk F1 Danger FNR Policy Benign FPR Latency
hybrid (default) 0.8631 0.9691 0.0408 (6/147 missed) 0.0610 (5/82) 10.8 ms
neural 0.8718 0.9500 0.0952 (14/147 missed) 0.0244 (2/82) 10.9 ms
baseline 0.5833 0.6784 0.4762 (70/147 missed) 0.3293 (27/82) <0.1 ms

Training & calibration

Datasets are generated from the proptest (pgregory.net/rapid) simulated environment harness in cmd/datagen and trained in train/:

go run ./cmd/datagen --train 60000 --val 5000 --cal 5000 --seed 200 --out /tmp/interlock-data
python -m train.finetune_ettin --base-model jhu-clsp/ettin-encoder-17m \
  --train /tmp/interlock-data/train.jsonl --val /tmp/interlock-data/val.jsonl \
  --eval-real /tmp/interlock-data/eval_real.jsonl --eval-ood /tmp/interlock-data/eval_ood.jsonl \
  --out /tmp/run/ettin17m.pt
python -m train.export_ettin --checkpoint /tmp/run/ettin17m.pt \
  --cal /tmp/interlock-data/cal.jsonl \
  --eval-real /tmp/interlock-data/eval_real.jsonl --eval-ood /tmp/interlock-data/eval_ood.jsonl \
  --out internal/model/embedded/interlock-ettin-17m-v2.ilkm

License

MIT. See LICENSE. The embedded classifier weights are fine-tuned from jhu-clsp/ettin-encoder-17m (MIT).