Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:0sec labs 0 runCampaign

From Leeroopedia
Knowledge Sources
Domains LLM_Security, Red_Team, Campaign_Engine
Last Updated 2026-10-29 00:00 GMT

Overview

Concrete tool for sweeping payloads across target models, judging responses, recording unique breaks, and optionally bandit-steering strategy selection, provided by the 0security llm-redteam engine.

Description

The runCampaign function is the campaign engine. In the standard path, it iterates over candidate payloads × models, sends each, judges the response, and records a break when the judge fires. Unique-breaks: once a model breaks it is skipped. In the bandit-steered path (requires jevFeedback), it uses a multi-armed bandit to adaptively select the most fruitful strategy combinations, bounded by maxAttempts (default 100). The CampaignResult reports attempts, breaks, broken models, and per-attempt reports.

Usage

Import this when you need to run an end-to-end red-team campaign against one or more target models. It is Step 5 of the LLM red-team campaign workflow.

Code Reference

Source Location

  • Repository: 0security
  • File: packages/llm-redteam/src/engine.ts:L308-450+

Signature

export async function runCampaign(
  behavior: Behavior,
  target: Target,
  opts?: CampaignOptions,
): Promise<CampaignResult>;

interface CampaignOptions {
  candidates?: Payload[];           // override candidate set
  judge?: JudgeFn;                  // override judge (default regexJudge)
  maxAttempts?: number;             // attempt cap (default 100 bandit, unlimited standard)
  banditSteering?: boolean;         // enable bandit strategy selection
  jevFeedback?: JevFeedbackFn;       // advisory feedback hook (required for bandit)
  stopWhenAllBroken?: boolean;
  seedBroken?: string[];            // pre-broken models to skip
  signal?: AbortSignal;
}

interface CampaignResult {
  behaviorId: string;
  target: string;
  attempts: number;
  breaks: BreakRecord[];
  brokenModels: string[];
  attemptReports: AttemptReport[];
  steeringWeights?: Record<string, number>;
}

interface BreakRecord {
  model?: string;
  payload: Payload;
  evidence: string;
  judge: string;
}

Import

import { runCampaign } from "@0/llm-redteam";

I/O Contract

Inputs

Name Type Required Description
behavior Behavior Yes /// The attack behavior to test
target Target Yes /// Mock or chat target to evaluate against
opts.candidates Payload[] No /// Override candidate set (default generateCandidates)
opts.judge JudgeFn No /// Override judge (default regexJudge)
opts.maxAttempts number No /// Attempt cap (default 100 bandit, unlimited standard)
opts.banditSteering boolean No /// Enable bandit strategy selection

Outputs

Name Type Description
return CampaignResult Attempts, breaks, broken models, attempt reports, steering weights

Usage Examples

Standard campaign

import { runCampaign, builtinBehaviors, chatTarget } from "@0/llm-redteam";

const target = chatTarget({
  baseUrl: "https://api.openai.com/v1",
  apiKey: process.env.OPENAI_API_KEY!,
  models: ["gpt-4o", "gpt-4o-mini"],
});

const result = await runCampaign(builtinBehaviors[0], target);
console.log(`Attempts: ${result.attempts}`);
console.log(`Breaks: ${result.breaks.length}`);
console.log(`Broken models: ${result.brokenModels}`);
for (const b of result.breaks) {
  console.log(`  ${b.model}: ${b.evidence}`);
}

Bandit-steered campaign

import { runCampaign, builtinBehaviors, mockTarget } from "@0/llm-redteam";

const target = mockTarget({
  models: [
    { name: "easy", followsVisible: true, decodes: ["tags"] },
    { name: "hard", followsVisible: false, decodes: [] },
  ],
});

const result = await runCampaign(builtinBehaviors[0], target, {
  banditSteering: true,
  jevFeedback: async (behavior, response) => ({
    label: "attempted-prohibited",
    probability: 0.9,
    advisory: true,
  }),
  maxAttempts: 50,
});
console.log(`Steering weights: ${JSON.stringify(result.steeringWeights)}`);

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment