RED-04 · Red-Teaming & Evals

CTF-Style Challenges for AI Agent Security: Building Reproducible Playgrounds and Scoring Agent Exploitation

How to design AI security CTF challenges that are reproducible, score real agent exploitation, and go beyond prompt injection puzzles to test tool-using agents.

The red-team evaluation loop: plan an attack, run it against the agent, observe the outcome, score it, then iterateplan01attack02observe03score04findings feed the next round — coverage grows until the agent stops failing

A team that can break their own agent on demand sleeps better than one waiting for an incident report. Capture-the-flag (CTF) challenges are the cheapest way to build that muscle. They turn fuzzy fears about prompt injection and runaway tool calls into concrete, repeatable exercises with a clear win condition: did the attacker reach the flag, or not?

The problem is that most “AI security CTF” content stops at a single chat box and a hidden password. Real agents browse, call tools, read untrusted documents, and chain actions. If your playground does not model that, it teaches the wrong lessons. This article is about designing CTF-style challenges that hold up: reproducible environments, scoring that reflects actual exploitation, and difficulty curves that map to real agent threat models. It sits alongside the automated tooling in a broader red-team framework practice for AI agents.

What makes a good AI agent security CTF challenge?

A good AI agent security CTF challenge is a self-contained, reproducible environment where an attacker has a precise objective (the flag), the agent under test has a realistic capability set (tools, memory, retrieval), and success is scored by whether the attacker forced an unauthorized state change or data disclosure — not merely whether the model “said something bad.” The challenge must reset cleanly to a known state between attempts, log every tool call and model turn, and define the flag in machine-checkable terms.

That definition does three jobs at once. Reproducibility means two researchers running the same challenge get the same baseline behavior, so a “win” is a property of the technique and not of a lucky random seed. Realistic capability means the agent can actually be exploited the way production agents are — through indirect prompt injection in retrieved content, tool misuse, or privilege confusion — rather than only through a direct “ignore your instructions” message. Machine-checkable flags mean scoring is objective: a file got written, an API got called, a secret string appeared in output that should never have left the sandbox.

Anything missing one of these legs becomes a demo, not a challenge. A demo is fine for awareness. A challenge is what lets you measure whether a defense actually moved the needle.

Why does prompt-injection-only CTF design fall short for agents?

Because prompt injection is the entry point, not the whole attack surface. The canonical learning tool here is Lakera’s Gandalf, a gamified prompt injection ladder where you coax a model into revealing a password across seven levels of hardening, plus a self-learning eighth level that retires attacks once they work. Gandalf is excellent pedagogy: it teaches that a single guardrail is brittle and that creativity beats keyword filters. But it models one thing — extracting a secret from a single LLM turn.

Production agents fail in ways Gandalf cannot express. OWASP’s 2025 Top 10 for LLM Applications still ranks prompt injection as LLM01, and it explicitly splits the risk into direct injection (the user types malicious instructions) and indirect injection (the model ingests hostile instructions hidden in a website, document, email, ticket, or code repository). The indirect case is where agents get genuinely dangerous: a retrieval-augmented agent or a tool-using agent may treat untrusted external content as trusted instructions and then act on them — call a tool, send an email, modify a file.

So a CTF that only tests “make the model say the password” trains defenders for the 2023 threat model. The interesting 2025 challenge is: a support agent reads a customer ticket that contains a hidden instruction; does the agent then call the refund tool, exfiltrate another customer’s data, or escalate its own permissions? That mirrors the real attack surface of AI agents, and it requires a playground with tools, state, and trust boundaries — not just a text box.

How do you design a reproducible security playground for agents?

Reproducibility is an engineering property you build in, not a wish. Treat the playground like a test fixture: deterministic where you can be, and explicit about the parts that cannot be.

Pin and snapshot everything around the model. Containerize the whole environment so the OS, tool binaries, seed data, and network policy are byte-identical on every run. Pin the agent scaffold and tool definitions in version control. The model weights and decoding are the one stochastic element you usually cannot freeze; isolate that uncertainty rather than letting it leak into the rest of the harness.

Reset to a known state between attempts. Every challenge run starts from a fresh snapshot: clean filesystem, reseeded database, cleared agent memory, reset tool quotas. Without this, a successful exploit poisons the next attempt and your scores stop meaning anything. A teardown-and-restore step is non-negotiable.

Make the flag machine-checkable and side-effect based. Define winning as an observable state change: a sentinel file written outside the sandbox, a specific tool invoked with specific arguments, a canary secret appearing in an outbound payload. Avoid “the judge model decides if this looks like a jailbreak” as your only signal — LLM judges are useful but should grade nuance, not gate the flag.

Log the full trace. Capture every model turn, every tool call with its arguments and results, and every state transition. The trace is what turns a win into a lesson: you can replay exactly how the agent was led from a benign ticket to an unauthorized action.

Control the model variable deliberately. Run each challenge across several seeds or several attempts and report attack success rate, not a single pass/fail. Public agent benchmarks already lean this way — CyberGym, for example, ships its evaluation harness and agent scaffolding so results can be reproduced rather than asserted. Borrow that discipline even for an internal playground.

How should you score agent exploitation rather than just jailbreaks?

Score by the impact reached and by reliability, not by whether a single clever prompt produced a single bad sentence. An agent that can be made to leak a secret once in fifty tries is a different risk from one that leaks on the first try every time, and your scoring should say so.

A practical rubric separates what was achieved from how reliably:

Dimension What it measures Example signal
Objective reached Did the attacker hit the flag’s defined impact? Refund tool called for an unauthorized account
Impact tier Severity of the state change Read-only disclosure vs. write/exfiltration vs. privilege escalation
Reliability Attack success rate across N attempts/seeds 3/50 vs. 47/50
Stealth Did monitoring/guardrails flag the attempt? Detected and blocked, detected but allowed, undetected
Path length Turns or tool calls needed to reach the flag 1-shot vs. multi-step chain

Reporting all five turns a binary “hacked / not hacked” into something a defender can act on. A challenge where the only winning path is a 30-turn chain that your monitor flags every time is a far healthier state than a 1-shot exploit that slips past undetected — even though both technically “reach the flag.”

This is also where agent CTFs diverge sharply from human ones. Modern offensive research increasingly evaluates LLM agents in multi-target settings — CTFExplorer, for instance, deploys dozens of vulnerable web services in one environment and asks an agent to autonomously discover, distinguish, and exploit them. The scoring there is necessarily about breadth and reliability across targets, not a single capture. Your internal scoring should anticipate that the “attacker” may itself be an automated agent probing many paths.

What threat models should your challenge ladder cover?

Build the ladder around how agents actually get owned, escalating from the obvious to the systemic. A defensible progression:

  • Level 1 — Direct injection. Classic Gandalf-style: get the agent to reveal a secret or ignore its system prompt through direct input. Tests baseline input hygiene.
  • Level 2 — Indirect injection via retrieval. Hide instructions in a document the agent fetches or in RAG context. Tests whether the agent separates data from instructions (OWASP’s indirect LLM01 case).
  • Level 3 — Tool misuse. Lead the agent to call a legitimate tool with attacker-chosen arguments — a refund, an email, a file write. Tests whether tool calls are authorized and validated, not just available, and pairs naturally with a tool-call fuzzing harness that probes the same surface automatically.
  • Level 4 — Privilege and trust confusion. Make the agent use one user’s authority on behalf of another, or treat sandboxed output as trusted input. Tests the boundary model.
  • Level 5 — Multi-step chaining. Combine the above: injected content triggers a tool call whose output feeds a second injection. Tests defense-in-depth and monitoring under realistic complexity.

Each level should have a clean win condition and a documented “intended” exploit path, while leaving room for unintended ones — the unintended captures are where you learn the most. Crucially, every level needs a paired defended variant so the playground measures defense effectiveness: run the same attacks against the agent with input sanitization, tool authorization, and a monitor enabled, and watch the attack success rate (hopefully) drop.

How do you keep an AI security CTF maintainable and honest?

The fastest way to ruin a playground is to let it drift from reality and from itself. Three habits keep it honest.

Version challenges like code, and retire stale ones. Models change monthly; an exploit that worked on last quarter’s model may fail today, and a defense that held may now leak. Lakera’s self-learning Gandalf level is the design pattern to imitate: treat the challenge as living, retire attacks that have been “solved,” and re-baseline when the underlying model changes. Tag each result with the exact model, scaffold, and challenge versions.

Separate the awareness track from the assurance track. A puzzle that teaches a developer what indirect injection feels like has different requirements from a regression suite that must run in CI and gate a release. Awareness challenges can be loose and fun; assurance challenges must be deterministic, machine-scored, and fast. Do not let one masquerade as the other.

Guard the playground itself. A realistic agent CTF hands an attacker — or an automated agent — tools and a sandbox. Keep it network-isolated, never wire it to production credentials, and assume any flag-checking secret could leak. The point of the exercise is to find failures cheaply; that only stays cheap if the lab cannot become a foothold.

Done well, an AI agent security CTF stops being a one-off awareness event and becomes part of the assurance loop: a reproducible way to ask “can we still break this?” before someone else asks it for you.


Sources referenced: Lakera Gandalf (gandalf.lakera.ai), OWASP Top 10 for LLM Applications 2025 (LLM01: Prompt Injection), and public agent-exploitation benchmarks including CyberGym and CTFExplorer.

Frequently asked

What is an AI security CTF?

An AI security CTF is a capture-the-flag exercise where an attacker tries to make an AI system — increasingly an autonomous agent — perform an unauthorized action or disclose protected data, with success defined by reaching a concrete, checkable flag. Unlike traditional CTFs, the target is a model or agent, and the winning techniques are things like prompt injection, tool misuse, and trust-boundary confusion rather than memory corruption or weak crypto.

How is an agent hacking challenge different from a normal prompt injection puzzle?

A prompt injection puzzle like Lakera's Gandalf tests whether you can manipulate a single model turn to reveal a secret. An agent hacking challenge adds tools, memory, retrieval, and state, so the goal becomes forcing the agent to act — call a tool, write a file, exfiltrate data — often via indirect injection hidden in content the agent reads. It tests the whole attack surface, not just one text box.

What is indirect prompt injection and why does it matter for agents?

Indirect prompt injection is when malicious instructions are hidden in external content the model ingests — a website, document, email, ticket, or code repository — rather than typed directly by the user. OWASP's 2025 LLM01 entry calls this out explicitly. It matters for agents because a tool-using or retrieval-augmented agent may treat that untrusted content as trusted instructions and then take real actions based on it.

How do you make a security playground reproducible?

Container the whole environment, pin tool binaries and the agent scaffold in version control, reset to a clean snapshot between every attempt, and define the flag as a machine-checkable side effect. Because model decoding is stochastic, run each challenge across multiple seeds or attempts and report an attack success rate rather than a single pass/fail, so a 'win' reflects the technique and not luck.

How should I score agent exploitation?

Score by impact and reliability, not by a single bad output. Track whether the objective flag was reached, the severity tier of the state change (read-only disclosure vs. write/exfiltration vs. privilege escalation), the attack success rate across N attempts, whether monitoring detected the attempt, and how many steps the exploit needed. Reporting these together turns a binary 'hacked or not' into something defenders can act on.

Can I use an LLM as the judge for whether a challenge was solved?

Use an LLM judge to grade nuance, not to gate the flag. The flag itself should be an objective, machine-checkable signal — a sentinel file written, a specific tool call made, or a canary secret appearing in output. LLM judges are useful for assessing severity or intent but are too variable to be the sole arbiter of a pass/fail score.

Are there existing benchmarks I can learn from instead of building from scratch?

Yes. Public agent-exploitation benchmarks such as CyberGym and CTFExplorer ship reproducible harnesses and scaffolding, and CyberGym in particular publishes its evaluation harness so results can be replicated. Even if you build an internal playground, borrow their discipline: pinned environments, machine-checkable success, multi-attempt scoring, and full trace logging.

How do I keep an AI security CTF from going stale?

Treat challenges as living code. Models change monthly, so version every challenge, tag results with the exact model and scaffold used, retire attacks once they are reliably solved, and re-baseline when the underlying model changes. Lakera's self-learning Gandalf level is a good pattern: it retires working attacks automatically so the challenge stays meaningful over time.