Skip to content
/ clawbands Public

ClawBands is a security middleware for OpenClaw AI agents.

License

Notifications You must be signed in to change notification settings

SeyZ/clawbands

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🦞 + πŸͺ’ ClawBands

ClawBands Logo

Put safety bands on OpenClaw

ClawBands is a security middleware for OpenClaw AI agents. It hooks into OpenClaw's plugin system to intercept every tool execution (file writes, shell commands, network requests) and enforces human-in-the-loop approval before dangerous actions execute.

License: MIT TypeScript Node.js

Why?

OpenClaw can execute shell commands, modify files, and access your APIs. OS-level isolation (containers, VMs) protects your host machine, but it doesn't protect the services your agent has access to.

ClawBands solves this by hooking into OpenClaw's before_tool_call plugin event. Before any dangerous action executes (writes, deletes, shell commands, API calls), the agent pauses and waits for your decision. In a terminal, you get an interactive prompt. On messaging channels (WhatsApp, Telegram), the agent asks you YES/NO and relays your answer via a dedicated clawbands_respond tool. Every choice is logged to an immutable audit trail. Think of it as sudo for your AI agent: nothing happens without your explicit permission.

Features

  • πŸ”’ Synchronous Blocking - Agent pauses until you approve
  • βš™οΈ Granular Control - Allow reads, ask on writes, deny deletes
  • πŸ’¬ Channel Support - Works in terminal, WhatsApp, Telegram via clawbands_respond tool
  • πŸ“Š Full Audit Trail - Every decision logged (JSON Lines format)
  • ⚑ Zero Latency - Runs in-process, no API calls

Quick Start

Prerequisites

  • Node.js >= 18.0.0
  • OpenClaw installed

Installation

# Install globally
npm install -g clawbands

# Run interactive setup
clawbands init

# Restart OpenClaw
openclaw restart

Done! ClawBands is now protecting your OpenClaw instance.

How It Works

Terminal Mode (TTY)

Agent calls tool: write('/etc/passwd', 'hacked')
  β†’ before_tool_call hook fires
  β†’ ClawBands checks policy: write = ASK
  β†’ Interactive prompt:
    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
    β”‚ 🦞 CLAWBANDS SECURITY ALERT         β”‚
    β”‚                                     β”‚
    β”‚ Module: FileSystem                  β”‚
    β”‚ Method: write                       β”‚
    β”‚ Args: ["/etc/passwd", "hacked"]     β”‚
    β”‚                                     β”‚
    β”‚ ❯ βœ“ Approve                         β”‚
    β”‚   βœ— Reject                          β”‚
    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
  β†’ You reject β†’ { block: true }
  β†’ Decision logged to audit trail

Channel Mode (WhatsApp / Telegram)

Agent calls tool: bash('rm -rf /tmp/data')
  β†’ before_tool_call β†’ policy = ASK β†’ blocked (pending approval)
  β†’ Agent asks: "ClawBands requires approval. YES or NO?"

User replies YES:
  β†’ Agent calls clawbands_respond({ decision: "yes" })
  β†’ before_tool_call intercepts β†’ approves pending entry
  β†’ Agent retries bash('rm -rf /tmp/data') β†’ approved βœ“

User replies NO:
  β†’ Agent calls clawbands_respond({ decision: "no" })
  β†’ before_tool_call intercepts β†’ denies pending entry
  β†’ Agent does NOT retry β†’ cancelled βœ“

The clawbands_respond tool is registered automatically via api.registerTool() when the gateway supports it.

Security Policies

ClawBands uses three decision types:

Policy Behavior
ALLOW Execute immediately (e.g., file reads)
ASK Prompt for approval (e.g., file writes)
DENY Block automatically (e.g., file deletes)

Default policy (Balanced):

  • FileSystem: read=ALLOW, write=ASK, delete=DENY
  • Shell: bash=ASK, exec=ASK
  • Network: fetch=ASK, request=ASK
  • Everything else: ASK (fail-secure default)

CLI Commands

clawbands init        # Interactive setup wizard
clawbands policy      # Manage security policies
clawbands stats       # View statistics
clawbands audit       # View decision history
clawbands reset       # Reset statistics
clawbands disable     # Temporarily disable
clawbands enable      # Re-enable

Example: View Audit Trail

$ clawbands audit --lines 5

16:05:00 | FileSystem.read              | ALLOWED    |   0.0s
16:06:00 | FileSystem.write             | APPROVED   |   3.5s (human)
16:07:00 | Shell.bash                   | REJECTED   |   1.2s (human)
16:08:00 | FileSystem.delete            | BLOCKED    |   0.0s - Policy: DENY

Example: View Statistics

$ clawbands stats

πŸ“Š ClawBands Statistics

Total Calls:    142

Decisions:
  βœ… Allowed:      35 (24.6%)
  βœ… Approved:     89 (62.7%) - by user
  ❌ Rejected:     12 (8.5%)  - by user
  🚫 Blocked:       6 (4.2%)  - by policy

Average Decision Time: 2.8s

Data Storage

All data stored in ~/.openclaw/clawbands/:

~/.openclaw/clawbands/
β”œβ”€β”€ policy.json       # Your security rules
β”œβ”€β”€ decisions.jsonl   # Audit trail (append-only)
β”œβ”€β”€ stats.json        # Statistics
└── clawbands.log     # Application logs

Use as a Library

import { Interceptor, createToolCallHook } from 'clawbands';

// Create interceptor with default policy
const interceptor = new Interceptor();

// Create a hook handler for OpenClaw's before_tool_call event
const hook = createToolCallHook(interceptor);

// Register with the OpenClaw plugin API
api.on('before_tool_call', hook);

Protected Tools

ClawBands intercepts every tool mapped in TOOL_TO_MODULE:

  • FileSystem: read, write, edit, glob
  • Shell: bash, exec
  • Browser: navigate, screenshot, click, type, evaluate
  • Network: fetch, request, webhook, download
  • Gateway: listSessions, listNodes, sendMessage

Any unmapped tool falls through to defaultAction (ASK by default).

Architecture

src/
β”œβ”€β”€ core/
β”‚   β”œβ”€β”€ Interceptor.ts    # Policy evaluation engine
β”‚   β”œβ”€β”€ Arbitrator.ts     # Human-in-the-loop (TTY prompt / channel queue)
β”‚   β”œβ”€β”€ ApprovalQueue.ts  # In-memory approval state for channel mode
β”‚   └── Logger.ts         # Winston-based logging
β”œβ”€β”€ plugin/
β”‚   β”œβ”€β”€ index.ts              # Plugin entry point (hook + tool registration)
β”‚   β”œβ”€β”€ tool-interceptor.ts   # before_tool_call handler + clawbands_respond intercept
β”‚   └── config-manager.ts     # OpenClaw config management (register/unregister)
β”œβ”€β”€ storage/        # Persistence (PolicyStore, DecisionLog, StatsTracker)
β”œβ”€β”€ cli/            # Command-line interface
β”œβ”€β”€ types.ts        # TypeScript definitions
└── config.ts       # Default policies

Development

# Clone repo
git clone https://github.com/SeyZ/clawbands.git
cd clawbands

# Install dependencies
npm install

# Build
npm run build

# Test CLI locally
node dist/cli/index.js init

# Link for global testing
npm link
clawbands --help

Security Guarantees

βœ… Zero Trust - Every action evaluated βœ… Synchronous Blocking - Agent waits for approval βœ… No Bypass - Plugin hooks intercept all tool calls βœ… Immutable Audit - JSON Lines append-only format βœ… Human Authority - Critical decisions need approval βœ… Fail Secure - Unknown actions default to ASK/DENY

Contributing

We believe in safe AI. PRs welcome!

  1. Fork the repo
  2. Create your feature branch: git checkout -b feature/amazing
  3. Commit changes: git commit -m 'Add amazing feature'
  4. Push: git push origin feature/amazing
  5. Open a Pull Request

See CONTRIBUTING.md for details.

License

MIT - See LICENSE for details.

Acknowledgments

  • Built for OpenClaw agents
  • Inspired by the need for human oversight in AI systems
  • Thanks to the AI safety community

Built with ❀️ for a safer AI future.

About

ClawBands is a security middleware for OpenClaw AI agents.

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published