Back
60/65
Lesson 60
10 min
Security Deep Dive
Three-layer defense with DCG, SLB, and CAAM for safe agent autonomy
Ready to level up?
Mark complete to track your learning progress.
Three-layer defense with DCG, SLB, and CAAM for safe agent autonomy
Mark complete to track your learning progress.
Understand the three-layer security model that makes agent autonomy safe — DCG blocks dangerous commands, SLB gates risky operations behind peer review, and CAAM prevents credential exposure.
Single safety measures fail. The flywheel uses three independent layers so that no single point of failure can let a dangerous operation through.
Block destructive commands mechanically
Two-person rule for risky operations
Credential isolation and rotation
Each layer catches what others miss
DCG is a pre-execution hook (Claude Code, Codex, Antigravity, and other agent CLIs) that runs before every command execution. It parses each command's structure (using ast-grep for embedded scripts) and checks it against its packs at sub-millisecond latency — agents don't even notice it's there.
# DCG blocks destructive commands automatically# Agent tries: rm -rf /# → BLOCKED: core.filesystem:rm-rf-root-home# DCG understands command STRUCTURE, not just stringsdcg test "rm -rf /" --explain# → BLOCKED: Root path deletiondcg test "rm -rf /tmp/build" --explain# → ALLOWED: Scoped to /tmp (not root)dcg test "git push --force origin feature-x" --explain# → BLOCKED: --force can overwrite remote history on any branchdcg test "git push --force-with-lease origin feature-x" --explain# → ALLOWED: the lease refuses to clobber commits you haven't seen# DCG packs (rule bundles)dcg packs --enabled# → core.git, core.filesystem (always on), plus packs you enable# Health checkdcg doctor --format json
rm -rf /tmp/build is scoped while rm -rf / is destructive.For commands that are sometimes needed but always dangerous, SLB enforces a two-person rule. One agent creates a launch request, and a human (or second agent) must approve before execution.
# Initialize SLB in a projectslb init# Default "independent" policy refuses local approvals; opt in firstslb config set general.approval_policy same_host# Every requester and reviewer works in an SLB sessionslb session start --agent agent-1 # → prints the session ID and key# Agent 1 wants to force-push (DCG would normally block)slb request "git push --force origin feature-x" --reason "Rewrite history on my feature branch" -s <agent-1-id># → Launch request created: slb-a7f3# Agent 1 sees:# ⚠️ CRITICAL: needs 2 approvals before execution# Each reviewer (human or another agent) approves from their own sessionslb approve slb-a7f3 --session-id <reviewer-id> --session-key <reviewer-key># Once both approvals are in, the command can executeslb execute slb-a7f3 -s <agent-1-id># Policy for unattended workflowsslb config set general.timeout_action auto_reject # Reject if nobody reviews in time# Reviewing agents stream pending requestsslb watch --session-id <reviewer-id> --json# → NDJSON events for every request awaiting review
CAAM manages multiple subscription logins per agent CLI with automatic rotation on rate limits. This prevents a single compromised or rate-limited account from stopping all agents.
# List saved profilescaam ls# Switch the active Claude accountcaam activate claude personal@gmail.com# Mark the exhausted account so rotation skips itcaam cooldown set claude/work@company.com --minutes 15# Let caam pick the best available accountcaam next claude# Save a newly logged-in accountcaam backup claude third@company.com# Check live quota and reset timescaam limits claude# In agent swarms, each agent runs in its own isolated profile# caam exec claude agent-1 -- ...# caam exec claude agent-2 -- ...# No single account gets overwhelmed
When an agent runs a command, it passes through each security layer in sequence. Here is the decision flow:
# Real scenario: Agent needs to drop and recreate a test database# Step 1: Agent tries "DROP DATABASE test_db"# → DCG: BLOCKED (database.postgresql:drop-database)# Step 2: Agent creates SLB requestslb request "DROP DATABASE test_db" --reason "Recreate the throwaway test DB" -s <agent-id># → slb-b2e9 created, awaiting approval (CRITICAL: 2 approvals)# Step 3: Reviewers see it's a test DB and approveslb approve slb-b2e9 --session-id <reviewer-id> --session-key <reviewer-key># Step 4: Command executes safely through SLBslb execute slb-b2e9 -s <agent-id># Step 5: Agent continues with API calls via CAAM# → CAAM routes to claude-2 (claude-1 is cooling down)
All three layers produce audit logs, giving you a complete picture of every security decision made during agent operation.
# DCG logs every block decisiondcg stats --days 1# → Blocked/allowed/bypassed counts and the rules that fired# SLB tracks every request, approval, and executionslb history --json# → Full history with who requested, who approved, when# CAAM logs account switches and rate limit eventscaam history --limit 50# → Shows rotation events, usage spikes, cooldown periods# Combined: full picture of agent safety# "At 14:32, agent-3 tried 'rm -rf /data',# DCG blocked it, no SLB request created.# At 14:35, agent-1 hit rate limit on claude-1,# CAAM rotated to claude-2 in 12ms."
Three independent layers, each catching what the others miss. DCG for speed, SLB for judgment, CAAM for resource protection. Together they make it safe to give agents real autonomy.