crabtrap-llm-proxy
LLM-as-a-judge HTTP/HTTPS proxy that secures AI agents by intercepting and evaluating outbound requests against security policies before they reach external APIs.
What this skill does
# CrabTrap LLM Proxy
> Skill by [ara.so](https://ara.so) — Daily 2026 Skills collection.
CrabTrap is a transparent HTTP/HTTPS forward proxy that sits between AI agents and external APIs. Every outbound request is intercepted, checked against deterministic static rules, then evaluated by an LLM judge against a natural-language security policy. Blocked requests return a 403 with a reason; all decisions are logged to PostgreSQL.
## Architecture Overview
```
Agent → CrabTrap Proxy (:8080) → [Static Rules] → [LLM Judge] → External API
↓
Admin UI (:8081)
↓
PostgreSQL
```
**Key concepts:**
- **Static rules** — deterministic prefix/exact/glob URL matching, checked first (no LLM call)
- **LLM judge** — natural-language policy evaluated only when no static rule matches
- **Audit log** — every request, decision, and response stored in PostgreSQL
- **SSRF protection** — blocks RFC 1918, loopback, link-local, and other private ranges
## Installation
### Docker Compose (Recommended)
```yaml
# docker-compose.yml
services:
crabtrap:
image: quay.io/brexhq/crabtrap:latest
ports:
- "8080:8080" # proxy
- "8081:8081" # admin UI
environment:
- DATABASE_URL=postgres://crabtrap:password@postgres:5432/crabtrap
- OPENAI_API_KEY=${OPENAI_API_KEY}
volumes:
- ./config/gateway.yaml:/app/config/gateway.yaml
depends_on:
- postgres
postgres:
image: postgres:16
environment:
POSTGRES_USER: crabtrap
POSTGRES_PASSWORD: password
POSTGRES_DB: crabtrap
volumes:
- pgdata:/var/lib/postgresql/data
volumes:
pgdata:
```
```bash
docker compose up -d
# Copy the generated CA certificate (needed for HTTPS interception)
docker compose cp crabtrap:/app/certs/ca.crt ./ca.crt
```
### Initial Setup
```bash
# Create an admin user and capture the token
admin_token=$(docker compose exec -it crabtrap ./gateway create-admin-user my-admin \
| tail -n1 | cut -d" " -f2)
# Create an agent user (returns a gateway_auth_token)
token=$(curl -X POST http://localhost:8081/admin/users \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${admin_token}" \
-d '{"id": "[email protected]", "is_admin": false}' \
| jq -r '.channels[] | select(.channel_type == "gateway_auth") | .gateway_auth_token')
echo "Agent proxy token: $token"
# Test the proxy
curl -x "http://${token}:@localhost:8080" \
--cacert ca.crt \
https://httpbin.org/get
```
## Configuration
### Full Configuration Reference
```yaml
# config/gateway.yaml
proxy:
port: 8080
read_timeout: 30s
write_timeout: 30s
idle_timeout: 120s
rate_limit:
requests_per_second: 50
burst: 100
# CIDR ranges allowed even though they're private (e.g. internal APIs)
ssrf_allowlist:
- "10.0.0.0/8" # only if you explicitly need internal access
tls:
ca_cert_path: /app/certs/ca.crt
ca_key_path: /app/certs/ca.key
cert_cache_size: 10000 # per-host cert cache
approval:
mode: llm # "llm" or "passthrough"
timeout: 30s
llm_judge:
provider: openai
model: gpt-4o
fallback_mode: deny # "deny" or "passthrough" when LLM unavailable
circuit_breaker:
failure_threshold: 5
reset_timeout: 10s
database:
url: ${DATABASE_URL} # supports env var expansion
audit:
output: stderr # "stderr", "stdout", or a file path like "/var/log/crabtrap.json"
log_level: info # debug | info | warn | error
```
### Environment Variables
```bash
DATABASE_URL=postgres://user:password@host:5432/dbname
OPENAI_API_KEY=sk-... # if using OpenAI as LLM judge
ANTHROPIC_API_KEY=sk-ant-... # if using Anthropic
```
## CLI Commands
```bash
# Start the proxy
./gateway serve --config /app/config/gateway.yaml
# Create an admin user (outputs web token on last line)
./gateway create-admin-user <username>
# Run database migrations
./gateway migrate
# Replay audit log entries against a policy (eval mode)
./gateway eval --policy-id <id> --limit 100
```
## Admin API
All admin endpoints require `Authorization: Bearer <admin_token>`.
### User Management
```bash
# List all users
curl http://localhost:8081/admin/users \
-H "Authorization: Bearer ${admin_token}"
# Create a user
curl -X POST http://localhost:8081/admin/users \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${admin_token}" \
-d '{
"id": "[email protected]",
"is_admin": false
}'
# Delete a user
curl -X DELETE http://localhost:8081/admin/users/[email protected] \
-H "Authorization: Bearer ${admin_token}"
```
### Static Rules
```bash
# List static rules for a user
curl "http://localhost:8081/admin/users/[email protected]/rules" \
-H "Authorization: Bearer ${admin_token}"
# Create an allow rule (prefix match)
curl -X POST "http://localhost:8081/admin/users/[email protected]/rules" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${admin_token}" \
-d '{
"pattern": "https://api.github.com/repos/myorg/",
"pattern_type": "prefix",
"action": "allow",
"methods": ["GET"],
"description": "Allow reading our org repos"
}'
# Create a deny rule (glob match)
curl -X POST "http://localhost:8081/admin/users/[email protected]/rules" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${admin_token}" \
-d '{
"pattern": "https://api.github.com/repos/*/delete",
"pattern_type": "glob",
"action": "deny",
"description": "Never allow repo deletion"
}'
# Create an exact match rule
curl -X POST "http://localhost:8081/admin/users/[email protected]/rules" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${admin_token}" \
-d '{
"pattern": "https://slack.com/api/chat.postMessage",
"pattern_type": "exact",
"action": "allow",
"methods": ["POST"],
"description": "Allow posting Slack messages"
}'
```
**Pattern types:**
- `prefix` — URL must start with the pattern
- `exact` — URL must match exactly
- `glob` — wildcard matching with `*`
**Rule priority:** `deny` rules always take priority over `allow` rules.
### LLM Policies
```bash
# Get current policy for a user
curl "http://localhost:8081/admin/users/[email protected]/policy" \
-H "Authorization: Bearer ${admin_token}"
# Set/update a policy
curl -X PUT "http://localhost:8081/admin/users/[email protected]/policy" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${admin_token}" \
-d '{
"policy": "This agent assists with GitHub repository management for the myorg organization.\n\nALLOWED:\n- Read operations (GET) on any github.com endpoint\n- Creating issues and pull request comments in myorg repositories\n- Posting messages to the #eng-alerts Slack channel only\n\nDENIED:\n- Any write operations outside the myorg GitHub organization\n- Deleting any resources\n- Accessing credentials, secrets, or environment variables\n- Any requests to non-whitelisted domains"
}'
# List policy versions
curl "http://localhost:8081/admin/users/[email protected]/policy/versions" \
-H "Authorization: Bearer ${admin_token}"
```
### Audit Log
```bash
# Query audit entries
curl "http://localhost:8081/admin/audit?limit=50&offset=0" \
-H "Authorization: Bearer ${admin_token}"
# Filter by user
curl "http://localhost:8081/admin/[email protected]&limit=20" \
-H "Authorization: Bearer ${admin_token}"
# Filter by decision
curl "http://localhost:8081/admin/audit?decision=deny&limit=20" \
-H "Authorization: Bearer ${admin_token}"
```
## Connecting an Agent
### Python Agent Example
```python
import os
import httpx
PROXY_TOKEN = os.environ["CRABTRAP_TOKEN"]
PROXY_URL = f"http://{PROXY_TOKEN}:@localhost:8080"
CA_CERT_PATH = "./ca.crt"
# httpx client with CrabTrap proxy
client = httpx.Client(
proxies={
"http:/Related in AI Agents
skill-development
IncludedComprehensive meta-skill for creating, managing, validating, auditing, and distributing Claude Code skills and slash commands (unified in v2.1.3+). Provides skill templates, creation workflows, validation patterns, audit checklists, naming conventions, YAML frontmatter guidance, progressive disclosure examples, and best practices lookup. Use when creating new skills, validating existing skills, auditing skill quality, understanding skill architecture, needing skill templates, learning about YAML frontmatter requirements, progressive disclosure patterns, tool restrictions (allowed-tools), skill composition, skill naming conventions, troubleshooting skill activation issues, creating custom slash commands, configuring command frontmatter, using command arguments ($ARGUMENTS, $1, $2), bash execution in commands, file references in commands, command namespacing, plugin commands, MCP slash commands, Skill tool configuration, or deciding between skills vs slash commands. Delegates to docs-management skill for official documentation.
reprompter
IncludedTransform messy prompts into well-structured, effective prompts — single or multi-agent. Use when: "reprompt", "reprompt this", "clean up this prompt", "structure my prompt", rough text needing XML tags and best practices, "reprompter teams", "repromptception", "run with quality", "smart run", "smart agents", multi-agent tasks, audits, parallel work, anything going to agent teams. Don't use when: simple Q&A, pure chat, immediate execution-only tasks. See "Don't Use When" section for details. Outputs: Structured XML/Markdown prompt, quality score (before/after), optional team brief + per-agent sub-prompts, agent team output files. Success criteria: Single mode quality score ≥ 7/10; Repromptception per-agent prompt quality score 8+/10; all required sections present, actionable and specific.
adaptive-compaction
IncludedAdaptive add-on policy and recovery layer that decides WHEN to compact, prune, snapshot, or fork -- replacing fixed-percent auto-compaction across Claude Code, Codex, and MCP-capable hosts. Trigger on auto-compact timing or damage: "when should I compact", "is it safe to compact now or start a fresh session", "auto-compact fires too early/mid-task", "switching to an unrelated task but the window still has space", "context rot", "answers get worse the longer the session runs", "the agent forgot the plan or my decisions after it summarized", "add a layer on top that manages context without changing the agent", raising autoCompactWindow to give the policy room, or installing/tuning a cross-tool compaction policy or PreCompact hook -- even when "compaction" is never said but the problem is context-window pressure or post-summarization memory loss. Do NOT use to summarize a conversation, build RAG, write a summarization prompt (decides WHEN not HOW), or answer max-context-length trivia.
agent-skill-creator
IncludedCreate cross-platform agent skills from workflow descriptions. Activates when users ask to create an agent, automate a repetitive workflow, create a custom skill, or need advanced agent creation. Triggers on phrases like create agent for, automate workflow, create skill for, every day I have to, daily I need to, turn process into agent, need to automate, create a cross-platform skill, validate this skill, export this skill, migrate this skill. Supports single skills, multi-agent suites, transcript processing, template-based creation, interactive configuration, cross-platform export, and spec validation.
llm-wiki
IncludedUse when building or maintaining a persistent personal knowledge base (second brain) in Obsidian where an LLM incrementally ingests sources, updates entity/concept pages, maintains cross-references, and keeps a synthesis current. Triggers include "second brain", "Obsidian wiki", "personal knowledge management", "ingest this paper/article/book", "build a research wiki", "compound knowledge", "Memex", or whenever the user wants knowledge to accumulate across sessions instead of being re-derived by RAG on every query.
skill-master
IncludedAgent Skills authoring, evaluation, and optimization. Create, edit, validate, benchmark, and improve skills following the agentskills.io specification. Use when designing SKILL.md files, structuring skill folders (references, scripts, assets), ingesting external documentation into skills, running trigger evals, benchmarking skill quality, optimizing descriptions, or performing blind A/B comparisons. Keywords: agentskills.io, SKILL.md, skill authoring, eval, benchmark, trigger optimization.