Skip to main content

What You’ll Learn

  • The five major categories of prompt injection attacks
  • How to configure InjectionDefenseConfig with sensitivity levels and actions
  • The difference between block and log_only actions
  • How Declaw’s proxy intercepts injection payloads at the network layer before they reach the upstream LLM API

Prerequisites

  • Declaw running locally or in the cloud (see Deployment)
  • DECLAW_API_KEY and DECLAW_DOMAIN set in your environment
This example is available in Python. TypeScript support coming soon.

Attack Categories

Code Walkthrough

Phase 1: Baseline (no injection defense)

Without injection defense, the script processes all five payloads without any interception. In a real application, these would be forwarded to the LLM API, potentially manipulating its behavior.

Phase 2: With injection defense enabled

Injection scanning is opt-in per domain and outbound-only — the domains list names the egress hosts whose request bodies are scanned (here, the LLM API). An empty or unset domains list means no scanning happens, even with enabled=True.

The user input processing script

The script simulates an application that processes user inputs containing injection payloads. In a real scenario, these inputs would be sent to an LLM API through the Declaw proxy:

Inspecting the security configuration

Sensitivity Levels

Actions

How the Defense Works

Declaw’s injection defense operates at the network layer, not the application layer:
This means the defense applies regardless of which HTTP library the code in the sandbox uses, and regardless of which LLM provider it calls.

Expected Output