Runtime scans
Execute hosted red-team probes through the actual agent code running in development, CI, staging, or production.
A runtime scan exercises your application's agent directly. ZeroLeaks invokes a local RuntimeScanTarget through an authenticated relay, preserving agent behavior that a system prompt or limited HTTP interface may not capture.
See the quickstart for a complete example and the API reference for every method and option.
Implement a target
interface RuntimeScanTarget {
describe(): RuntimeTargetDefinition | Promise<RuntimeTargetDefinition>;
invoke(input: RuntimeTargetInvocation):
| string
| RuntimeTargetResponse
| Promise<string | RuntimeTargetResponse>;
reset?(sessionId: string): void | Promise<void>;
}invoke() receives:
| Field | Contents |
|---|---|
message | The current attack prompt |
messages | Complete history for this isolated session |
sessionId | Stable across a multi-turn sequence |
signal | Cancellation and timeout signal |
| Scan and event identifiers | For logging or correlation |
The SDK calls reset() when the engine starts a new conversation.
Use createRuntimeTarget() to wrap functions and metadata separately, or defineRuntimeTarget() when your application already implements the interface:
const target = defineRuntimeTarget(myTarget);
await zeroleaks.runtimeScans.run(target);Return a structured response
Return text alone or a structured response:
return {
text: result.text,
messages: result.messages,
finishReason: result.finishReason,
usage: result.usage,
toolCalls: result.toolCalls.map((call) => ({
id: call.id,
name: call.name,
arguments: call.arguments,
result: call.result,
error: call.error,
providerExecuted: call.providerExecuted,
})),
};When messages is omitted, the SDK appends the returned text as an assistant message. Return the complete post-invocation history when your framework emits tool and assistant messages that later turns need.
Scan an AI SDK agent
Install ai@^7 and import the adapter. Projects on AI SDK 6 should stay on @zeroleaks/sdk 0.3.x.
import { ZeroLeaks } from "@zeroleaks/sdk";
import { aiSdk } from "@zeroleaks/sdk/ai-sdk";Wrap an existing Agent. This is the recommended path because the same Agent object serves production requests and security probes:
const target = aiSdk({
agent: productionAgent,
name: "Production support agent",
instructions: SUPPORT_INSTRUCTIONS,
callOptions: { tenantId: "security-test" },
});
const { report } = await zeroleaks.runtimeScans.run(target);The adapter reads agent.tools, converts every inputSchema and outputSchema to JSON Schema, and records tool calls and tool results from each AI SDK step.
Or create a ToolLoopAgent target by passing the settings ToolLoopAgent accepts:
import { openai } from "@ai-sdk/openai";
import { stepCountIs, tool } from "ai";
import { z } from "zod";
const target = aiSdk({
name: "Support agent",
model: openai("gpt-5"),
instructions: SUPPORT_INSTRUCTIONS,
stopWhen: stepCountIs(12),
tools: {
lookupCustomer: tool({
description: "Read a customer profile",
inputSchema: z.object({ id: z.string() }),
execute: ({ id }) => lookupCustomer(id),
}),
},
});
await zeroleaks.runtimeScans.run(target);All tools are active unless your AI SDK agent limits them through its own activeTools, prepareStep, approval, or call-option logic.
Set invocationMode: "stream" when scan invocations must pass through the agent's streaming implementation:
const target = aiSdk({
agent: productionAgent,
invocationMode: "stream",
});The adapter consumes the stream and submits the final text, generated response messages, usage, and tool trace to ZeroLeaks.
Scan an OpenAI agent
import OpenAI from "openai";
import { ZeroLeaks } from "@zeroleaks/sdk";
import { openAI } from "@zeroleaks/sdk/openai";
const client = new OpenAI();
const zeroleaks = new ZeroLeaks();For the Responses API, use openAI.responses():
const target = openAI.responses({
client,
request: {
model: "gpt-5",
instructions: SUPPORT_INSTRUCTIONS,
tools: [
{
type: "function",
name: "lookup_customer",
description: "Read a customer profile",
parameters: {
type: "object",
properties: { id: { type: "string" } },
required: ["id"],
additionalProperties: false,
},
strict: true,
},
{ type: "web_search" },
],
},
toolExecutors: {
lookup_customer: ({ id }) => lookupCustomer(String(id)),
},
});
await zeroleaks.runtimeScans.run(target);The adapter follows function_call items with function_call_output items until the response completes. Provider-executed tools such as web search are also included in the trace.
For Chat Completions, use openAI.chatCompletions():
const target = openAI.chatCompletions({
client,
request: {
model: "gpt-5",
tools: [
{
type: "function",
function: {
name: "lookup_customer",
description: "Read a customer profile",
parameters: {
type: "object",
properties: { id: { type: "string" } },
required: ["id"],
},
},
},
],
},
toolExecutors: {
lookup_customer: ({ id }) => lookupCustomer(String(id)),
},
});The adapter runs the assistant and tool-message loop until the model produces a final response.
By default, executor errors are returned to the model as tool results and recorded in the report. Set toolErrorMode: "throw" when your production loop terminates immediately on tool failure.
For custom OpenAI orchestration, streaming event handling, Agents SDK code, or application-specific memory, wrap your production handler with createRuntimeTarget().
Choose a scan mode
| Mode | Coverage | Options |
|---|---|---|
full (default) | Secrets in context, adaptive injection, target-specific boundary probes, and the complete production probe catalog, on every attack surface | Ignores attackSurfaces. Uses the production knowledge profile unless you ask for research. Raises maxAdaptiveCandidates to at least 10. |
quick | Omits the production catalog and caps adaptive boundary probes at 4. Use it for development smoke tests. | Honors attackSurfaces, knowledgeProfile, and maxAdaptiveCandidates |
Limit concurrency
Use eventConcurrency to tune local execution when your target has stricter rate limits:
await zeroleaks.runtimeScans.run(target, {
eventConcurrency: 4,
workerStallTimeoutMs: 6 * 60_000,
scan: { scanMode: "full" },
});How the relay works
The attack engine creates each probe. Your SDK process claims it and calls your target locally. The SDK polls only while runtimeScans.run() is active.
- Reconnaissance, secrets-in-context, injection, and agent-probe sessions stay separate. Independent sessions run concurrently by default, and events within a session stay ordered.
- The three reconnaissance questions arrive as ordinary invoke events before any attack.
- Invoke and reset events are claimed so two runners cannot normally execute the same event. A reset claimed by a runner that stops responding is handed to the next poll after one minute.
- An invoke is never repeated, because the runner may already have called tools. If it is not completed within six minutes, it fails and the scan records the error.
- Aborting, timing out, or detecting a stalled hosted worker cancels the run instead of leaving it marked as running.
Stored data
The target definition and options you send are stored so the hosted workflow can replay them against your agent. API reads redact credential-shaped values from target and options. When the scan ends, the stored copy is rewritten with those values redacted. The report's target receives the same redaction. Keep real credentials out of instructions and metadata even with these protections.