Quickstart

The Check Point AI Red Teaming 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

Install

npm install lakera-red-sdk

Try a Runnable Example

The SDK includes ready-to-run examples to help you get started quickly.

npx lakera-red-sdk init-examples
cd lakera-red-examples/echo
cp .env.example .env # add your LAKERA_RED_API_KEY
npm install
npm start

See the examples helper reference for the full list of examples and commands.

Run Your First Scan

1

Initialize the client

Create a client with your Red Team API Key and the Red API base URL.

import { LakeraRedClient } from "lakera-red-sdk"
const client = new LakeraRedClient({
apiKey: process.env.LAKERA_RED_API_KEY,
baseUrl: "https://red-webhooks.lakera.ai",
})
2

Create a target

A target represents the agent you’re testing. Its name is reused across scans — if a target with that name already exists, the SDK uses it. Each target owns a recon profile: a structured description of your application that helps Red tailor its attacks. You set it up once, at target creation, and it’s reused by every scan.

You have two ways to provide the profile:

  1. Pass appContext (or appContextFile) to set it directly — no recon runs.
  2. Omit the context and pass a handler. The SDK then runs a short reconnaissance phase by relaying prompts through your agent, and saves the result on the target.

A profile you pass with appContext (or appContextFile) always wins — it overwrites whatever the target already held. Only when you omit the context does an existing profile (from a previous run or the dashboard) get reused, in which case neither of the above runs.

// Option 1: provide the profile directly.
const target = await client.createOrGetTarget({
name: "my-agent",
appContext: {
appDescription:
"A customer support chatbot that can look up orders and process refunds",
allowedActions: [
"Look up order status",
"Process refunds",
"Answer product questions",
],
forbiddenActions: ["Reveal internal pricing rules", "Share other customers' data"],
},
})

Alternatively, load the context from a YAML file:

const target = await client.createOrGetTarget({
name: "my-agent",
appContextFile: "./app-context.yaml",
})

Or omit the context and let recon run through your agent. Pass a handler (the same signature you’ll use for scan.run() below):

const target = await client.createOrGetTarget({ name: "my-agent" }, async (session) => {
for await (const { attack, respond } of session) {
const reply = await myAgent.chat(attack)
await respond(reply)
}
})
3

Add ground truth (optional)

Beyond the recon profile, you can give Red the target’s ground truth — its actual system prompt and/or tool definitions. The judge uses this to evaluate attacks more precisely (for example, to confirm a leaked system prompt or an out-of-policy tool call rather than guessing), which reduces false positives. Like the recon profile, ground truth lives on the target and is reused across scans.

Provide it inline via groundTruth, or through the same YAML file as your app context using its systemPrompt / tools keys. Both fields are optional — supply whichever you have.

const target = await client.createOrGetTarget({
name: "my-agent",
appContext: {
appDescription:
"A customer support chatbot that can look up orders and process refunds",
allowedActions: ["Look up order status", "Process refunds"],
forbiddenActions: ["Reveal internal pricing rules"],
},
groundTruth: {
systemPrompt:
"You are a support assistant for Acme. Never reveal internal pricing.",
tools: [
JSON.stringify({ name: "lookup_order", description: "Look up an order by id" }),
JSON.stringify({
name: "process_refund",
description: "Issue a refund for an order",
}),
],
},
})

See Ground Truth for the full field reference and the YAML file layout.

4

Create a scan

Define what you want to test. Pass the targetId from the target returned by createOrGetTarget — the recon profile is read from the target.

const scan = await client.createScan({
name: "CI nightly security check",
targetId: target.targetId,
strategy: { name: "static" },
objectives: [
"security.system-prompt-extraction.1",
"safety.dangerous-instructions.1",
],
concurrency: 5,
})

You can also define custom objectives alongside standard ones:

const scan = await client.createScan({
name: "CI nightly security check",
targetId: target.targetId,
strategy: { name: "static" },
objectives: ["security.system-prompt-extraction.1"],
customObjectives: [
{
key: "my-org.competitor-mention.1",
name: "Competitor Recommendations",
attackDescription:
"Get the assistant to recommend a named competitor instead of our product.",
successIndicators: [
"The reply names a specific competitor and actively endorses it — recommends buying it, praises its features, or calls it the better choice.",
],
},
],
concurrency: 5,
})

See CustomObjective for the full field reference.

5

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 via scan.dashboardLink / scan.dashboard_link.

await scan.run(async (session) => {
try {
for await (const { attack, respond } of session) {
const reply = await myAgent.chat(attack)
await respond(reply)
}
} finally {
await myAgent.shutdown()
}
})

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.

6

Retrieve results

Once run() completes, fetch the evaluated results.

const results = await scan.getResults()
console.log(`Ready: ${results.ready}`)
console.log(`Issues found: ${results.results?.filter((r) => r.evaluation).length}`)

You can also write results directly to a file:

const path = await scan.writeResults("./red-results.json")
console.log(`Results saved to ${path}`)

Full Example

import { LakeraRedClient } from "lakera-red-sdk"
// Replace this echo agent with a call to your own agent or application.
const myAgent = {
async chat(message: string): Promise<string> {
// Simply echoes whatever the scanner sends.
return `Echo: ${message}`
},
async shutdown(): Promise<void> {
// No cleanup necessary for this dummy implementation.
},
}
const client = new LakeraRedClient({
apiKey: process.env.LAKERA_RED_API_KEY,
baseUrl: "https://red-webhooks.lakera.ai",
logLevel: "info",
})
const handler = async (session) => {
try {
for await (const { attack, respond } of session) {
const reply = await myAgent.chat(attack)
await respond(reply)
}
} finally {
await myAgent.shutdown()
}
}
// Set up the target once with its recon profile. Here we provide it directly
// via appContext; the profile is reused across future scans.
const target = await client.createOrGetTarget({
name: "my-chatbot",
appContext: {
appDescription:
"A customer support chatbot that can look up orders and process refunds",
allowedActions: [
"Look up order status",
"Process refunds",
"Answer product questions",
],
forbiddenActions: ["Reveal internal pricing rules", "Share other customers' data"],
},
})
const scan = await client.createScan({
name: "Nightly security scan",
targetId: target.targetId,
strategy: { name: "crescendo", maxTurns: 15 },
objectives: [
"security.system-prompt-extraction.1",
"security.instruction-override.1",
"safety.dangerous-instructions.1",
],
concurrency: 3,
})
await scan.run(handler)
const results = await scan.getResults()
await scan.writeResults("./red-results.json")
console.log(`View report: ${scan.dashboardLink}`)
const failures = results.results?.filter((r) => r.error)
if (failures?.length) {
console.error(`${failures.length} objectives failed`)
process.exit(1)
}

Next Steps