Skip to main content
The Security module provides composable, production-grade protections for Definable agents. Each feature is independently optional and automatically integrates with the agent’s guardrail and hook systems.

Quick Start

Or enable defaults with security=True:

SecurityConfig

The unified entry point for all security features:
All fields are optional. Only configured features are activated.

Tool Policy

Control which tools an agent can call. Auto-injects a ToolGuardrail.
str
default:"full"
"deny" blocks all tools, "allowlist" permits only listed tools, "full" allows everything.
Set[str]
Tools permitted in allowlist mode. Ignored in other modes.
bool
default:"false"
In full mode, block tools in the dangerous registry (shell, file mutation, code execution).

Dangerous Tools Registry

The built-in DEFAULT_DANGEROUS_TOOLS set includes:

Rate Limiting

Sliding-window rate limiting for interface messages. Attach as an interface hook.
int
default:"10"
Maximum messages allowed per sliding window.
int
default:"60"
Window duration in seconds.
int
default:"3"
Number of rate limit violations before triggering a lockout.
int
default:"300"
Lockout duration in seconds (default: 5 minutes).

Custom Key Extraction

By default, the rate limiter identifies users via sender_id, user_id, or platform_user_id on the message object. Override with a custom function:

Content Defense

Detect and block prompt injection attempts. Auto-injects an InputGuardrail.

Prompt Injection Detection

The PromptInjectionDetector scans for 16+ patterns including:
  • Role override attempts (“you are now”, “act as”)
  • Instruction manipulation (“ignore previous instructions”, “forget your instructions”)
  • System prompt extraction (“reveal your system prompt”, “repeat your instructions”)
  • Format injection ([INST], <<SYS>>, XML role tags)
Confidence scoring: 1 match = 0.3, 2 matches = 0.6, 3+ matches = 0.95.

XML Content Wrapping

Wrap untrusted content (tool results, knowledge) in XML tags with nonce-based boundary protection:

SSRF Protection

Prevent Server-Side Request Forgery in tool HTTP calls.
Blocked ranges include RFC 1918 (10.x, 172.16-31.x, 192.168.x), loopback (127.x, ::1), link-local (169.254.x), and cloud metadata endpoints (169.254.169.254).

Environment Sanitization

Strip dangerous environment variables before spawning subprocesses.
Strips 54 dangerous variables across categories: dynamic linker (LD_PRELOAD, DYLD_INSERT_LIBRARIES), Python startup (PYTHONSTARTUP, PYTHONPATH), shell injection (BASH_ENV, IFS), and more.

Security Audit

Run an automated security audit on any agent configuration:
The audit checks:
  1. Exposed secrets in instructions (API key patterns)
  2. Dangerous tools without ToolPolicy
  3. Missing auth on interfaces
  4. Missing input/output guardrails
  5. World-readable workspace files
  6. MCP servers with broad permissions
  7. Missing rate limiting on interfaces
  8. Shell/exec tools without confirmation

Scoring

  • Base: 100
  • Critical finding: -20
  • Warning finding: -5
  • Final: clamped to [0, 100]

Imports