OpenClaw Security Middleware. A Hybrid AI Security Sentry for Autonomous Agents.
ClawShield is a hybrid AI security layer that prevents autonomous agents from performing high-risk operations (unintended deletions, payments, subscriptions, deceptive buttons) through real-time multi-factor risk assessment combining OCR, visual AI, and contextual analysis.
- Multi-Factor Risk Scoring: 4-factor assessment (keywords, position, history, visual AI)
- Local Vision AI: Ollama integration for detecting deceptive UI elements
- Historical Trust Building: Actions become trusted after repeated safe use
- Adaptive Thresholds: Dynamic risk-based decision making (high/medium/low risk)
- Native macOS Integration: Seamless user confirmation dialogs
- Real-time Visual Audit: Live screen analysis with OCR and AI
- Lightweight & Fast: Efficient risk assessment with intelligent LLM triggering
- OpenClaw Integration: CLI wrapper and middleware for universal agent security
- Unified CLI: Single command interface for all ClawShield operations
- Command Interception: ClawShield wraps OpenClaw commands or acts as middleware, intercepting click operations before execution.
-
Target Capture: Extracts click coordinates
$(x, y)$ from intercepted OpenClaw commands or agent actions. -
Visual Context Capture: Crops a
$200 \times 200$ pixel region around cursor for UI analysis. -
Multi-Modal Analysis:
- OCR Text Extraction: Uses Tesseract to extract UI text
- Visual AI Classification: Local LLM (Ollama) analyzes button appearance for deception
- Contextual Assessment: Screen position, historical trust patterns
-
Four-Factor Risk Assessment:
- Keyword Matching (50%): Weighted dangerous words (Delete=1.0, Confirm=0.9, etc.)
- Position Risk (25%): Clicks near screen center are higher risk
- Historical Trust (10%): Previously allowed actions gain trust
- LLM Visual Risk (15%): AI-based deception detection
-
Adaptive Decision Making:
- High Risk (>0.7): macOS native dialog for user confirmation
- Medium Risk (0.3-0.7): Warning but automatic execution
- Low Risk (<0.3): Direct pass with logging
- Execution Control: Allows safe clicks to proceed, blocks dangerous ones, and provides detailed feedback to the calling agent or user.
The hybrid risk score
Where:
-
$R_{\text{words}}$ : Weighted sum of dangerous keywords in detected text -
$R_{\text{position}}$ : Normalized distance from screen center (closer = higher risk) -
$R_{\text{history}}$ : Trust factor based on previous interactions (negative = trusted) -
$R_{\text{LLM}}$ : Visual deception score from local LLM analysis (0-1)
ClawShield v1.0 supports two integration modes with OpenClaw:
OpenClaw Command β ClawShield Wrapper β Security Assessment β Safe Execution
- Intercepts OpenClaw CLI commands
- Parses click coordinates from command syntax
- Applies multi-factor risk assessment
- Executes only safe clicks, blocks dangerous ones
OpenClaw Agent β ClawShield Plugin β Click Hook β Security Check β Decision
- Integrates as a plugin within OpenClaw's execution pipeline
- Provides hook methods for click events
- Returns allow/block decisions with reasoning
- Maintains full compatibility with OpenClaw API
The clawshield command provides a unified interface:
run --wrap openclaw: Wrap OpenClaw commands with securitytest: Run comprehensive test suitedemo: Interactive demonstrationsentinel: Real-time protection mode
ClawShield requires Tesseract for text recognition:
brew install tesseractFor visual deception detection using local LLM:
# Install Ollama
brew install ollama
# Pull a vision model (llava recommended)
ollama pull llava
# Start Ollama service (keep this running)
ollama serve# Clone the repo
git clone [https://github.com/thefooliman/ClawShield.git](https://github.com/thefooliman/ClawShield.git)
cd ClawShield
# Create and activate virtual environment
python3 -m venv venv
source venv/bin/activate
# Install dependencies
pip install -r requirements.txtClawShield now provides a unified command-line interface for all operations:
# Make the CLI executable (first time only)
chmod +x clawshield
# Run OpenClaw commands with security wrapping
./clawshield run --wrap openclaw click 100 200
./clawshield run --wrap openclaw "click(100, 200)"
# Run tests
./clawshield test
# Run demonstration
./clawshield demo
# Run real-time protection sentinel
./clawshield sentinel
# Show help
./clawshield --helpWrap OpenClaw commands with ClawShield security:
# Basic click wrapping
./clawshield run --wrap openclaw click 500 300
# Complex OpenClaw command wrapping
./clawshield run --wrap openclaw "mouse click --button left 800 400"
# Batch command wrapping
./clawshield run --wrap openclaw "click(100,200); click(300,400); click(500,600)"First, verify that the local AI vision model is working:
python test_ollama_integration.pyThis will check Ollama availability and test the visual classification system.
Simulate an autonomous AI agent exploring the screen:
python test_agent.pyChoose the guided demo to see ClawShield in action:
- Safe clicks in neutral areas
- Dangerous button interception
- Trust building through repeated allowances
- Random exploration with real-time protection
Run the live protection system that monitors mouse movements:
# Set Python path
export PYTHONPATH=$PYTHONPATH:.
# Start the sentinel
python src/main.py- Move your mouse over UI elements
- Press 'q' to quit
- See real-time risk assessment in the overlay window
Use ClawShield's safe_click() function in your AI agent code:
from src.core.click import safe_click
# Replace direct clicks with safe_click
if safe_click(x, y):
print("Click executed safely")
else:
print("Click was blocked by risk assessment")- Open a webpage with "Delete", "Confirm", or "Subscribe" buttons
- Run the test agent or main script
- Hover over dangerous buttons to see interception
- Observe the macOS native dialog for high-risk actions
- Phase 0: Basic OCR + Keyword matching + Native Dialog (MVP) - v0.1
- Phase 1: Local Vision LLM (Ollama) integration with multi-factor risk scoring - v0.4
- Phase 2: OpenClaw Protocol integration with CLI wrapper - v1.0
This is an open-source project created by a high school developer. Feel free to open issues or submit pull requests!
This project is licensed under the MIT License.