Skip to main content

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 run rafter agent exec, Rafter:
  1. Evaluates the command against security policies
  2. Scans staged files (for git commands)
  3. Assesses risk level (low/medium/high/critical)
  4. Blocks or requires approval based on risk
  5. Logs the execution to audit log

Risk Levels

Commands that can cause catastrophic damage:
  • rm -rf / - Delete entire filesystem
  • :(){ :|:& };: - Fork bomb
  • dd if=/dev/zero of=/dev/sda - Wipe disk
  • mkfs.* - Format filesystems
  • > /dev/sda - Overwrite disk
These are always blocked, even with --force.
Commands with significant risk:
  • rm -rf <directory> - Recursive deletion
  • sudo rm - Delete with elevated privileges
  • chmod 777 - Insecure permissions
  • curl ... | sh - Pipe to shell
  • git push --force - Force push
  • npm publish - Publish packages
  • docker system prune - Delete Docker data
Requires user approval unless --force flag is used.
Commands that need elevated privileges:
  • sudo - Any sudo command
  • chmod - Change permissions
  • kill -9 - Force kill processes
  • systemctl - System service management
Moderate risk level: Requires approval, allowed in minimal mode.
Standard commands with minimal risk:
  • npm install - Install packages
  • git commit - Commit changes
  • ls, cat, grep - Read operations
  • echo, touch - Basic file operations
Allowed immediately across all risk levels.

Usage Examples

Safe Command

Executes immediately:

Git Commit with Auto-Scan

Scans staged files before committing:
If secrets are detected in staged files, the commit is blocked:
Note: rafter agent scan still works but is deprecated — it will be removed in a future major version.

High-Risk Command

Requires approval:
You’ll see:

Force Execution

Skip approval with --force (logged in audit):
The --force flag skips approval but is logged in the audit trail. Use responsibly.

Skip File Scanning

Skip pre-execution scanning for git commands:

Command Policies

Configure how Rafter handles commands:

Policy Modes

Custom Blocked Patterns

Add patterns to always block:

Custom Approval Patterns

Patterns requiring approval:

Audit Logging

All command executions are logged:
Audit entries include:
  • Timestamp
  • Command executed
  • Risk level
  • Action taken (allowed/blocked/overridden)
  • User justification (for overrides)

Integration with Agents

OpenClaw

When integrated with OpenClaw, commands are automatically routed through Rafter:

Claude Code

Claude Code integration uses PreToolUse hooks to intercept commands before execution, plus MCP tools for agent-initiated scans. See Claude Code Integration for setup, and MCP Integration for the MCP server.

Exit Codes

Rafter uses standard exit codes:
  • 0 - Success
  • 1 - Command blocked or execution failed
Use in scripts:

Best Practices

Recommended Practices

  1. Always use for git commits: Evaluates risk and scans staged files
  2. Never bypass with --force in production: Use only when necessary
  3. Review audit logs: Check rafter agent audit after suspicious activity
  4. Configure policies: Adjust commandPolicy.mode for your environment
  5. Test in development: Ensure policies work before deploying to agents

Advanced Configuration

Risk Level vs Policy Mode

Understanding the Difference

  • Risk Level (agent.riskLevel): Controls overall security stance
  • Policy Mode (agent.commandPolicy.mode): Controls specific command handling
Example:
  • riskLevel: aggressive + mode: approve-dangerous = Very secure
  • riskLevel: minimal + mode: allow-all = Permissive

Custom Risk Assessment

Future feature: Define custom risk patterns and severity levels.

Troubleshooting

Command Incorrectly Blocked

If a safe command is blocked:
  1. Check current policy:
  2. Switch to a more permissive mode:
  3. Report false positive: rafter-cli/issues

Secrets Not Detected

If secrets aren’t caught during git commits:
  1. Ensure scanning is enabled (default):
  2. Test scanner separately:

Next Steps

OpenClaw Integration

Set up with OpenClaw agents

Command Reference

Complete CLI command reference