Pattern 1: The Tool Gateway
Never give an agent direct access to tools. Route all tool calls through a gateway that enforces authorization, logging, and rate limiting.
The gateway is the single point where you can:
- Reject unauthorized tool calls
- Log every action with full context
- Rate limit per-session or per-agent
- Sanitize inputs before tool execution
- Filter sensitive data from tool outputs before returning to agent
Pattern 2: Isolated Execution Sandboxes
High-risk tool execution (shell commands, code execution) should happen in isolated environments that are destroyed after each use.
Key properties of a good sandbox:
- No network access (or severely restricted)
- No persistent storage (ephemeral by default)
- CPU/memory limits enforced
- Runs as non-root user
- Destroyed after each use
Pattern 3: Human-in-the-Loop Checkpoints
For irreversible or high-stakes actions, require human approval before execution.
Define clear thresholds. Actions above threshold go to review queue. This prevents "oops, the agent deleted the production database" scenarios that are irreversible.
Pattern 4: Immutable Audit Trail
Every agent action should be logged to an append-only audit trail that cannot be modified by the agent itself.
{
"timestamp": "2026-02-01T14:32:11Z",
"session_id": "sess_abc123",
"agent_id": "agent_prod_7",
"action": "file_read",
"parameters": {"path": "/app/data/report.csv"},
"result": "success",
"bytes_read": 4821,
"duration_ms": 12,
"ip_address": "10.0.1.5"
}
Store audit logs in a separate service with write-only API keys for the agent. Use append-only storage (S3 with object lock, CloudWatch Logs, external SIEM).
Pattern 5: Layered Permission Scopes
Implement a permission scope system similar to OAuth scopes for tool access.
Agent types and their allowed scopes:
READ_ONLY_AGENT: ["data:read", "search:query"]
ANALYST_AGENT: ["data:read", "search:query", "compute:run"]
WORKER_AGENT: ["data:read", "data:write:restricted", "email:send:internal"]
ADMIN_AGENT: ["data:*", "compute:*", "config:read"] # Requires 2FA approval for activation
Anti-Patterns to Avoid
❌ The "Just Trust the Agent" Pattern
Giving the agent root access, master API keys, or unrestricted tool access because "it's AI, it knows what it's doing." Real-world result: prompt injection extracts your master credentials.
❌ The "Debug Mode in Production" Pattern
Running with verbose logging, open admin panels, or debug endpoints because "it hasn't been set up for prod yet." Real-world result: anyone can read your agent's full context window including secrets.
❌ The "Shared Credentials" Pattern
Using the same API key for everything — agent reads, writes, deletes all using the same key. Real-world result: key exfil = full access to all operations.
❌ The "Log Nothing" Pattern
No audit trail means no forensics, no anomaly detection, no incident response capability.
