Skip to main content

What You’ll Learn

  • Creating a sandbox with InjectionDefenseConfig inside a SecurityPolicy
  • Sensitivity levels: LOW, MEDIUM, HIGH — and when to use each
  • Enforcement actions: BLOCK, LOG_ONLY
  • Scoping scanning to specific egress domains with domains=[...]
  • Example injection payloads the scanner detects (prompt override, base64-encoded attacks)
  • Shorthand boolean syntax: injection_defense=True for default settings

Prerequisites

  • Declaw instance running and DECLAW_API_KEY / DECLAW_DOMAIN set
  • (Optional) Guardrails service deployed for ML-powered scanning — falls back to regex without it

Code Walkthrough

This example is available in Python. TypeScript support coming soon.

1. Create a sandbox with injection defense

Pass an InjectionDefenseConfig to SecurityPolicy at sandbox creation time. The proxy enforces the policy for outbound HTTP requests to the domains you list.
Injection scanning is opt-in per domain and outbound-only: list the egress hosts you want scanned in domains (here, the LLM API the sandbox calls). An empty or unset domains list means no scanning happens at all, even with enabled=True.

2. Sensitivity levels

The sensitivity field controls how aggressively the scanner flags content.

3. Enforcement actions

When the scanner detects an injection attempt, the action field determines what happens.

4. Example payloads the scanner catches

The scanner decodes common encodings (base64, URL encoding) before analysis so obfuscated attacks are caught at the same sensitivity level as plain-text ones. Note this is a prompt-injection classifier — it targets attempts to manipulate the LLM, not application-layer attacks like SQL injection.

5. Shorthand boolean syntax

For default settings — sensitivity="medium", action="log_only" — pass True directly:
The boolean shorthand sets defaults but no domains, so on its own it scans nothing. To actually scan traffic, use the explicit config form and list the egress hosts (an empty domains list means no scanning):

6. Cleanup

Expected Output