Safe Command Execution
Rafter validates shell commands before execution to prevent dangerous operations.Quick Start
Execute a command with security checks:How It Works
When you runrafter agent exec, Rafter:
- Evaluates the command against security policies
- Scans staged files (for git commands)
- Assesses risk level (low/medium/high/critical)
- Blocks or requires approval based on risk
- Logs the execution to audit log
agent.riskLevel (minimal/moderate/aggressive, set by rafter agent init --risk-level or rafter agent config set agent.riskLevel) is stored and shown by rafter agent status, but the interceptor below doesn’t read it — it does not change which commands are blocked or need approval. Only the command’s assessed tier plus commandPolicy.mode/blockedPatterns/requireApproval/allowedPatterns (below) do that.Risk Levels
🔴 Critical (Blocked)
🔴 Critical (Blocked)
Commands that can cause catastrophic damage — hard-blocked unconditionally, no policy, mode, or
--force can allow them:rm -rf /orrm -rf /<home|etc|usr|boot|root|sys|proc|lib|lib64|bin|sbin|opt>— delete the filesystem or a critical top-level directory:(){ :|:& };:— fork bombdd if=... of=/dev/sd...— wipe a disk> /dev/sd...— overwrite a diskmkfs,fdisk,parted— format or repartition- Reverse shells —
bash -i >& /dev/tcp/...,nc -e/-ve ..., amkfifo+nc+ shell relay,socat ... exec:/system:, and equivalent Python/Perl/Node/PowerShell socket-to-shell one-liners - Any statement that names Rafter’s own directory (
~/.rafter,$HOME/.rafter, an absolute path, a glob or brace list that expands to it) and is not a known read-only command, and anycdinto it — see Command Policies
🟠 High (Requires Approval)
🟠 High (Requires Approval)
Commands with significant risk — denied unless a person approves at an interactive terminal (see Approval Model below):
rm -rf <anything>/rm -fr— recursive deletionsudo rm— delete with elevated privilegeschmod 777— insecure permissionscurl ... | sh/wget ... | sh(orbash/zsh/dash) — pipe to shellgit push --force/-f/--force-with-lease/--force-if-includes, or a+branchrefspec — force pushdocker system prune— delete Docker datanpm publish— publish a package- A pseudo-terminal wrapper around
rafter agent exec(script -c,expect,unbuffer, Python’spty.spawn) — it would fake the interactive terminal that approval requires
🟡 Medium (assessed, not gated by default)
🟡 Medium (assessed, not gated by default)
Commands the classifier labels medium risk: any use of
sudo, chmod, chown, systemctl, service, kill -9, pkill, killall. Today, a medium-tier command is allowed — it isn’t held for approval unless it separately matches a requireApproval pattern you’ve added yourself. The “medium” label still appears in the audit log and in --dry-run output.🟢 Low (Allowed)
🟢 Low (Allowed)
Everything that doesn’t match a higher tier —
npm install, git commit, ls, cat, grep, echo, touch, and so on.Allowed immediately.Usage Examples
Safe Command
Executes immediately:Git Commit with Auto-Scan
Scans staged files before committing:
Note: rafter agent scan still works but is deprecated — it will be removed in a future major version.
High-Risk Command
Requires approval:1 — with a message telling a person to run it themselves:
yes is not an approval and there is no flag that substitutes for a person at a terminal — anything an agent could pass on --force or on stdin, the agent could pass on its own, so neither route is honored.
Dry Run
Classify a command and print the verdict without running it, scanning staged files, or writing to the audit log:0 for allowed, 1 for blocked, 2 for requires-approval — useful for a script that wants the verdict without the side effects.
The -- Form
Pass the command as separate words after -- instead of one quoted string; Rafter re-quotes them before classifying, so what the classifier sees is exactly what the shell will run:
Force Execution (No Longer Skips Approval)
--force is still accepted — so old scripts and muscle memory don’t suddenly error — but it is a no-op. It prints a warning and then follows the normal approval path above (deny immediately outside a TTY; prompt at one):
Skip File Scanning
Skip pre-execution scanning for git commands:Command Policies
Configure how Rafter handles commands:Rafter’s own security settings are protected from the agent it guards:
rafter agent config set on a hooks, commandPolicy or riskLevel key and rafter agent disable <component> rate CRITICAL and are hard-blocked, the same tier as rm -rf /. The PreToolUse hook also denies file-write tool calls (including Codex apply_patch) to anything under ~/.rafter/, including through a symlink that points there. A shell command that names that directory is CRITICAL unless it is a known read-only command with no output redirect: rm, cp, tee, sed -i or echo x > onto ~/.rafter/config.json are blocked, as is cd ~/.rafter, while cat ~/.rafter/config.json | jq ., tail ~/.rafter/audit.jsonl, ls -la ~/.rafter and running ~/.rafter/bin/betterleaks are allowed. A statement that doesn’t name the directory is unaffected, so cat ~/.rafter/config.json && npm test runs. .rafter.yml and .rafterignore are not the directory. Change these settings yourself, outside an agent session.Dot-paths below are Node’s camelCase (
agent.commandPolicy.mode); Python takes the same keys in snake_case (agent.command_policy.mode). config get rejects the other runtime’s casing (Key not found); config set does not validate the path at all, so setting the wrong casing reports success and silently changes nothing. See Configuration Keys for details.Policy Modes
Critical commands are always blocked regardless of mode.commandPolicy.mode only changes what happens to a high-risk command that isn’t separately caught by blockedPatterns or requireApproval:
Custom Blocked Patterns
View or replace the list of patterns that are always denied (unanchored regex, matched case-insensitively against the sanitized command):agent config set writes any key path you give it, including a JSON array value, without validating it against anything — so a typo’d key silently does nothing. There’s no “add one pattern” command; to keep the built-in deny-list and add to it, include both in the array you set (or edit ~/.rafter/config.json directly). A project .rafter.yml can only make blockedPatterns/requireApproval stricter — see Policy File.
Custom Approval Patterns
Same idea for patterns that require approval:Allowlist Patterns
allowedPatterns is the inverse: an unanchored regex that forces a matching command to low and skips the approval prompt, for a known-safe command that would otherwise trip a broader rule (the motivating case is git push --force-with-lease to a feature branch whose main is protected server-side):
blockedPatterns always takes precedence, a critical command is never allowlisted, and a match is ignored when the command contains more than one statement (&&, ||, ;, |, &, newline). It’s also a grant, not a restriction, so it’s honored only from the machine owner’s global config: a project .rafter.yml can tighten blockedPatterns/requireApproval, but it cannot add to allowedPatterns unless the owner has separately set agent.commandPolicy.allowProjectOverride: true in the global config.
Audit Logging
All command executions are logged:- Timestamp
- Command executed
- Risk level
- Action taken (allowed/blocked/overridden)
Integration with Agents
OpenClaw
When integrated with OpenClaw, commands are automatically routed through Rafter:Claude Code
Claude Code integration uses thePreToolUse hook (rafter hook pretool) to intercept commands before execution, plus MCP tools for agent-initiated scans. The hook can only allow or deny — it has no way to prompt — so a command that would need approval from rafter agent exec is denied by the hook, with a reason telling a person to run it themselves: rafter agent exec '<command>' at an interactive terminal. If the hook hits an internal error while evaluating a call, it denies rather than allows, with reason rafter hook error: <type>: <message>; denying to be safe. A malformed .rafter.yml is a handled condition, not an error — it produces a warning and falls back to default settings, not a denial. See Claude Code Integration for setup, and MCP Integration for the MCP server.
Exit Codes
For a normal (non---dry-run) rafter agent exec:
0— the command ran and exited successfully1— denied (critical, blocked pattern, or approval denied/unavailable), or the command ran and failed — in the failure case, Rafter passes through the command’s own exit code, not always12— the pre-execution secret scan on a git command couldn’t run (e.g. a staged diff that failed to read); the commit is blocked without ever executing
--dry-run, the exit code is the classification itself, independent of whether anything would have run: 0 allowed, 1 blocked, 2 requires approval.
Use in scripts:
Best Practices
Recommended Practices
- Always use for git commits: Evaluates risk and scans staged files
- Don’t rely on
--force: it no longer skips approval — use--dry-runto check a command’s classification instead - Review audit logs: Check
rafter agent auditafter suspicious activity - Configure policies: Adjust
commandPolicy.modeand the pattern lists for your environment - Test in development: Use
--dry-runto confirm a policy change classifies commands the way you expect before deploying to agents
Advanced Configuration
Custom Risk Patterns
There’s no way to declare a custom severity label beyond low/medium/high/critical, or to change which built-in commands land in which tier. What you can do today is add toblockedPatterns (always deny), requireApproval (always gate), or allowedPatterns (force low and skip approval) — see Command Policies above.
Troubleshooting
Command Incorrectly Blocked
If a safe command is blocked or keeps asking for approval:-
Check current policy and which pattern matched — the
--dry-runoutput names the matched pattern: -
If it’s a critical hard-block (
rm -rf /, a reverse-shell pattern, etc.), it cannot be allowed by any config change — that’s by design. -
If it’s caught by
requireApprovalorblockedPatterns, switchingcommandPolicy.modetoallow-allwill not help — those two lists are checked unconditionally, regardless of mode. Either remove the matching entry fromrequireApproval/blockedPatterns, or add a narrowerallowedPatternsentry for just this command (see Allowlist Patterns above). -
If it’s only the default
approve-dangeroushigh-risk gate (no explicitrequireApprovalmatch),rafter agent config set agent.commandPolicy.mode allow-alldoes remove that gate. - Report false positive: rafter-cli/issues
Secrets Not Detected
If secrets aren’t caught during git commits:-
Ensure scanning is enabled (default):
-
Test scanner separately:
Next Steps
OpenClaw Integration
Set up with OpenClaw agents
Command Reference
Complete CLI command reference

