Building Trusted AI: Security Guide

Defense-in-depth architecture for running AI with system access. Threat models, protection layers, and operational best practices.

The Security Paradox of AI Assistants

Cloud AI is safe because it can't do anything. It generates text—safe, sandboxed, impotent. clawbot is different: it executes commands, modifies files, controls services. This power creates genuine security considerations.

But consider the alternative: copying AI-suggested commands from ChatGPT and pasting them into your terminal. No audit trail. No approval gates. No sandboxing. Just blind trust in AI-generated bash.

clawbot's security model assumes AI will make mistakes. The architecture provides defensive layers so mistakes don't become disasters. This isn't theoretical—it's battle-tested infrastructure used by 84,000+ developers running production systems.

Threat Model: Five Risk Scenarios

Understanding what can go wrong is the first step to preventing it. These are the realistic threats when AI has system access:

⚠️
Threat 1: Misinterpreted Instructions

Scenario: You say "delete old logs", intending /var/log/myapp/*.log. AI interprets this as /var/log/*.log and wipes system logs.

Impact: Data loss, broken monitoring, compliance violations.

Mitigation: Approval workflows for destructive commands, explicit scope in instructions, dry-run mode for risky operations.

🔓
Threat 2: Credential Exposure

Scenario: AI logs full command output including API keys. Logs sync to external monitoring service. Credentials leak.

Impact: Unauthorized access to third-party services, data breaches, financial loss.

Mitigation: Log sanitization, encrypted credential storage, environment variable isolation, separate secrets management.

🚀
Threat 3: Privilege Escalation

Scenario: AI discovers it can execute sudo commands without password (misconfigured system). Begins making system-wide changes beyond intended scope.

Impact: System instability, security policy violations, production outages.

Mitigation: Run clawbot as non-root user, restrict sudo access, use dedicated service accounts with minimal privileges.

💉
Threat 4: Command Injection via External Input

Scenario: AI processes untrusted data (email, webhook, API response) and incorporates it into shell commands without sanitization. Attacker crafts malicious input that executes arbitrary code.

Impact: Remote code execution, complete system compromise.

Mitigation: Input validation, parameterized commands, execution sandboxing, network isolation for untrusted channels.

🔁
Threat 5: Runaway Automation

Scenario: AI automation enters infinite loop (e.g., monitoring script that triggers itself). Consumes resources, generates spam, exhausts API quotas.

Impact: Resource exhaustion, cost overruns, service degradation.

Mitigation: Rate limiting, execution timeouts, circuit breakers, resource quotas.

Defense-in-Depth: Seven Protection Layers

clawbot implements multiple security layers. Threats must bypass all layers to cause harm. Each layer operates independently—failure of one doesn't compromise the others.

1

Sandboxed Execution

All system commands execute in isolated environments with restricted filesystem access. Skills can't read ~/.ssh/ or /etc/ unless explicitly granted permission.

2

Permission Controls

Fine-grained tool policies define what each skill can do. Whitelist approved commands, blacklist dangerous operations, require approval for sensitive actions.

3

Approval Workflows

Destructive operations pause for human confirmation. AI drafts the action, shows you exactly what will execute, waits for explicit approval.

4

Audit Logging

Every command, API call, and file access logs to immutable storage. Track what AI did, when, why, and with what result. Essential for forensics.

5

Credential Isolation

Secrets stored in encrypted vault (~/.clawbot/secrets.env) with access logging. Environment variables never appear in logs or error messages.

6

Network Boundaries

Separate trust zones for different channels. Public Discord has read-only access; private WhatsApp can execute commands. Enforce per-channel policies.

7

Resource Quotas

Rate limits prevent runaway automation. Maximum executions per minute, CPU/memory caps, API call quotas. Automation fails safe when limits reached.

10 Security Best Practices

Operational guidelines for running clawbot safely in production environments.

1️⃣
Run as Dedicated User, Not Root

Create a service account specifically for clawbot with minimal system privileges. Never run as root or your personal user account.

sudo useradd -r -s /bin/bash -d /home/clawbot -m clawbot
sudo -u clawbot clawbot gateway start

Why: Limits blast radius if AI executes malicious commands. Compromised clawbot user can't modify system files or access other users' data.

2️⃣
Enable Approval Workflows for Destructive Operations

Configure tool policies to require confirmation before executing dangerous commands:

# ~/.clawbot/config.json
{
"tools": {
"exec": {
"approval": "ask",
"approvalPatterns": ["rm -rf", "DROP TABLE", "kubectl delete", "git push --force"]
}
}
}
3️⃣
Encrypt Credential Storage

Never store API keys in plain text. Use clawbot's built-in secrets encryption:

clawbot secrets set GITHUB_TOKEN
clawbot secrets set OPENAI_API_KEY

Secrets encrypted at rest with AES-256. Decryption key derived from system keychain or passphrase.

4️⃣
Sanitize Logs to Remove Sensitive Data

Configure log redaction patterns to automatically remove credentials, tokens, and private data from logs:

# ~/.clawbot/config.json
{
"logging": {
"redact": ["password=.*", "token=.*", "apikey=.*", "Bearer .*"]
}
}
5️⃣
Implement Per-Channel Permission Policies

Public channels (Discord, Telegram public groups) should have read-only access. Restrict execution to authenticated channels (WhatsApp, private Slack).

Example Policy

WhatsApp: all tools enabled (authenticated, personal device)
Slack #ops: DevOps skills only (team visibility, trusted users)
Discord: read-only (public, untrusted)

6️⃣
Review Audit Logs Regularly

Schedule weekly reviews of ~/.clawbot/logs/exec.log. Look for unexpected commands, failed authentication attempts, or unusual patterns.

# Quick audit: show all exec commands from last 7 days
grep "exec:" ~/.clawbot/logs/gateway.log | tail -n 1000
7️⃣
Use Dry-Run Mode for New Automation

Before deploying automation to production, test with --dry-run flags. AI simulates execution without making actual changes.

"Run database cleanup script with --dry-run and show me what would be deleted."
8️⃣
Limit AI Model Access to Sensitive Data

For highly sensitive operations (customer data, financial records), use local Ollama models that never send data to external APIs.

Model Selection Policy

Customer data processing: Ollama llama3 (100% local)
Code reviews: GPT-4 (code not sensitive)
Public data analysis: Claude (best performance)

9️⃣
Implement Rate Limiting and Circuit Breakers

Prevent runaway automation with execution quotas:

# ~/.clawbot/config.json
{
"rateLimit": {
"maxExecutionsPerMinute": 10,
"maxAPICallsPerHour": 1000
}
}
🔟
Backup and Disaster Recovery

Regularly backup clawbot configuration, skills, and session data. Test restoration procedures.

# Backup entire clawbot directory
tar -czf clawbot-backup-$(date +%Y%m%d).tar.gz ~/.clawbot/

# Automate with cron
0 2 * * * tar -czf ~/backups/clawbot-$(date +\%Y\%m\%d).tar.gz ~/.clawbot/

Incident Response: When Things Go Wrong

Despite precautions, AI will occasionally do something unexpected. Here's how to respond quickly and minimize damage.

🚨 Immediate Actions for Security Incidents

1. Stop AI Execution: Kill clawbot gateway process immediately.

2. Assess Damage: Check audit logs to see exactly what executed.

3. Contain Breach: Rotate compromised credentials, revoke API tokens.

4. Restore from Backup: If data loss occurred, restore from last known good state.

5. Root Cause Analysis: Understand why AI made the mistake, update policies to prevent recurrence.

Emergency Stop Procedure

Keep this command accessible:

pkill -9 -f "clawbot gateway"

Stops all clawbot processes immediately. Use when AI enters dangerous loop or executes unintended commands.

Security Updates and Maintenance

Security is not a one-time configuration—it requires ongoing attention. Establish a maintenance routine:

Daily

Review audit logs for anomalies. Check for failed authentication attempts or unusual command patterns.

Weekly

Update clawbot to latest version. Review and rotate credentials for services with high exposure.

Monthly

Audit skill permissions. Remove unused skills. Review and update tool allowlists based on usage patterns.

Quarterly

Conduct security review: penetration testing, log analysis, incident simulations. Update incident response procedures.

Secure AI Infrastructure

Security isn't about preventing AI from acting—it's about ensuring AI acts safely. With proper defenses, clawbot provides unprecedented automation capability without sacrificing control.

Get Started Securely