Reference
Complete reference for the lakera-red-sdk package. Requires Node.js 22+.
LakeraRedClient
The main entry point. Creates targets and initiates scans.
LakeraRedClientOptions
client.createScan(options)
Creates a target (or reuses one by name) and creates a scan. Returns a Scan
instance. The scan does not begin execution until scan.run() is called.
CreateScanOptions
ReconContext
Describes your application so Red can tailor attacks to its capabilities and restrictions.
Inline:
YAML file (app-context.yaml):
Scan
Returned by client.createScan(). Manages scan execution and result retrieval.
scan.scanId
scan.run(handler)
Executes the scan. Polls the server for attack messages and invokes your handler for each concurrent session. Returns when the scan completes or times out.
Use the finally block to release agent resources (connections, memory) once a session
ends. This is especially important for crescendo sessions that maintain
state across multiple turns.
Behavior:
- If neither
appContextnorappContextFilewas provided tocreateScan(), the SDK first runs a reconnaissance phase using the same handler to learn about your application. Your handler will receive a few initial prompts as part of this phase before the actual attack sessions begin. - Manages concurrent sessions up to the configured
concurrencylimit - Retries on network errors with exponential backoff (1s–5s)
- Stops automatically after 3 minutes of inactivity (no messages from server)
- If your handler throws before calling
respond(), the SDK submits an error to the server on your behalf
scan.getResults()
Retrieves evaluated scan results.
Returns a ScanResults object:
scan.writeResults(path)
Writes results to a JSON file and returns the resolved absolute path.
Session
Passed to your scan.run() handler. Implements AsyncIterable<SessionMessage>, so you
consume it with for await...of.
SessionMessage
Each iteration yields an object with:
ScanResultEntry
Each entry in ScanResults.results:
Evaluation
Logging
The SDK outputs structured JSON logs to stderr by default, keeping stdout clean for your application output.
Configuration
Control log verbosity via the logLevel client option or the LAKERA_RED_LOG_LEVEL
environment variable:
Custom Logger
Provide your own logger to integrate with your existing observability stack:
createLogger / noopLogger
The SDK also exports utilities if you want to create or suppress loggers independently:
Examples Helper
Installing lakera-red-sdk also installs a lakera-red-sdk command for
bootstrapping example projects.
The bundled examples are pinned to the installed SDK version, so they always match the package you’re using.
Strategies
The strategy option accepts an object with a name field and optional
strategy-specific parameters:
Static
Sends a fixed set of adversarial prompts per objective. Each prompt is independent — there is no conversational escalation between turns. This makes static scans fast, deterministic, and well-suited for CI gates where you want quick, reproducible results.
Crescendo
A multi-turn strategy where the attacker gradually escalates over
several conversational turns within a single session. Each session may yield many
attack/respond pairs as the adversary probes for weaknesses through incremental
persuasion. Crescendo better simulates real-world persistent attackers and tests whether
your agent can maintain its guardrails under sustained conversational pressure.
Smoke
Server-defined canned probes for a quick sanity check. Objectives are ignored — the server uses its own fixed probe set.
Choosing a Strategy
Choose static for fast regression checks and crescendo for deeper adversarial
evaluation during pre-release security reviews.
Objective IDs
Pass these IDs in the objectives array when creating a scan. If you omit objectives,
all objectives across all categories are included (except when using the smoke
strategy, which uses its own fixed probe set).
Security
Safety
Responsible
For detailed descriptions of what each objective tests, see Attack Coverage.