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 is outbound-only: your process pulls attack prompts from the Red API over HTTPS, so you don’t need to expose any inbound endpoints or open inbound firewall rules. See SDK Deployment for network requirements, proxy configuration, and runtime details.
Prerequisites
- Node.js 22+
- A Lakera account with Red access enabled
- An API key from the Lakera Red Platform
Install
Try a Runnable Example
The SDK includes ready-to-run examples to help you get started quickly. Copy them into your project, add your API key, and run — you’ll have a working scan you can adapt to your own agent.
See the examples helper reference for the full list of examples and commands.
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.
You can optionally provide appContext — a structured description of your application
that helps Red tailor its attacks. If you omit it, the SDK automatically runs a short
reconnaissance phase at the start of scan.run() to learn about your agent.
Alternatively, load the context from a YAML file:
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