SDK Quickstart
The Lakera Red SDK (lakera-red-sdk) lets you run adversarial scans programmatically.
Use it to integrate red teaming into CI/CD pipelines, test custom agent flows, or
automate security assessments without the web UI.
The SDK uses a poll-based architecture — your client pulls attack messages from the Red API rather than receiving inbound calls. This means you don’t need to expose any endpoints or whitelist IPs. The SDK runs entirely within your network with only outbound HTTPS requests, avoiding the complexity of firewall rules, tunnels, or public-facing infrastructure that a webhook-based approach would require.
Prerequisites
- Node.js 22+
- A Lakera account with Red access enabled
- An API key from the Lakera Red Platform
Install
Run Your First Scan
Create a scan
Define what you want to test. The target name is reused across scans — if a
target with that name already exists, the SDK uses it.
Handle attack sessions
The scan.run() method drives the scan. For each concurrent session, your handler
receives adversarial prompts and submits your agent’s responses.
You can also follow the scan’s progress in the dashboard at
https://red.lakera.ai/scans/<scanId>/progress.
Each session may contain multiple turns (especially with the crescendo strategy).
The async iterator handles this naturally — just keep looping. The finally block
ensures your agent is properly shut down once the session completes or errors out.
Full Example
Next Steps
- See the SDK Reference for all configuration options and types
- Learn about attack categories Red tests for
- Set up Guard Integration to remediate findings automatically