How applejuice8/ctf-agent works
Purpose and entry points
CTF Agent is a local, materials-first solver for authorised CTF challenges. It inventories supplied challenge files, uses an LLM to classify the task and select a constrained Docker sandbox, iteratively investigates, extracts a flag, and writes logs/writeup artifacts. Primary entry point: scripts/run_all.sh; manual invocation support: scripts/solve_manual.py.
A separate, pinned live-CTF swarm integration is isolated under integrations/verialabs-ctf-agent, launched through scripts/run_veria_ctf_agent.sh.
Orchestration pipeline
The core control loop is split across:
• ctf_agent/solver/loop.py
• ctf_agent/classifier.py
• ctf_agent/solver/flag_extract.py
The runner first derives a safe material inventory and sends only the description plus metadata to the classifier. The classifier selects a CTF theme and minimal initial sandbox capabilities. The solver loop then gives the model bounded tool turns, preserves evidence, detects a flag, and controls completion or model handoff.
Model routing and continuity
ctf_agent/models/client.py implements provider access and route rotation across Gemini keys, Groq, and OpenRouter. ctf_agent/config.py supplies route, credential, budget, and runtime settings.
When quota, availability, or iteration limits require replacement, ctf_agent/handoff.py creates a compact state transfer containing prior assessments, commands, outputs, scope, and next action. This makes model changes a continuation of one solve rather than independent attempts.
Sandbox planning and execution boundary
Sandbox scope is planned before execution:
• ctf_agent/sandbox/planner.py
• ctf_agent/sandbox/manager.py
• ctf_agent/sandbox/executor.py
The planner converts theme/capability choices into a manifest; the manager builds or reuses a Docker image keyed by that manifest; the executor runs commands inside it. Challenge materials are mounted read-only, temporary work stays in disposable container /tmp, and host-side execution is avoided. The solver can request one logged, evidence-driven capability expansion.
Sandbox images are defined by docker/Dockerfile.sandbox. Docker is therefore the principal isolation runtime.
Web egress boundary
Web challenges are exceptional: only explicitly declared HTTP(S) targets are reachable. docker/egress_proxy.py and docker/Dockerfile.egress-proxy provide the private allow-list proxy layer. Connectivity is checked before consuming solver turns; loopback, private, and undeclared destinations are rejected. Normal sandbox operation has no network.
Inputs, state, and outputs
Required challenge input is under challenge_materials/, including challenge_materials/CHALLENGE_DESCRIPTION.md. Shared domain structures are defined in ctf_agent/types.py.
Persistent run evidence is written beneath logs/: classification decision, sandbox plan, transcript, handoff brief, and generated writeup. ctf_agent/writeup.py turns final evidence into a human-readable result. Resume safety is based on matching the description and material inventory, preventing evidence reuse across different challenges.
Optional knowledge and external integration
ctf_agent/skills/build_index.py and ctf_agent/skills/router.py optionally index a local ctf-skills checkout and provide post-classification technique hints; this does not affect sandbox selection.
integrations/verialabs-ctf-agent is a separate submodule for authorised CTFd competitions, with its own Python/dependency stack, multi-model coordination, and optional flag submission. It is intentionally not part of the local solver’s runtime path.
Main entry points: loop.py Solver control loop · classifier.py Task classifier · executor.py Sandbox executor · manager.py Sandbox manager
Components 22
Local solver
Materials-first CTF solve pipeline.
- Automated runner
scripts/run_all.sh - Manual solver
scripts/solve_manual.py - Challenge materials · Includes the required challenge description.
- Shared types
ctf_agent/types.py - Task classifier · Uses description and inventory metadata only.
ctf_agent/classifier.py - Solver control loop · Bounds tool turns, preserves evidence, and controls completion.
ctf_agent/solver/loop.py - Flag extraction
ctf_agent/solver/flag_extract.py - Model router · Rotates Gemini, Groq, and OpenRouter routes.
ctf_agent/models/client.py - Runtime settings · Supplies routes, credentials, budgets, and runtime settings.
ctf_agent/config.py - Solve handoff · Carries assessments, evidence, scope, and next action to a replacement model.
ctf_agent/handoff.py - Run evidence · Stores decisions, plans, transcript, handoff brief, and writeup.
- Writeup generator
ctf_agent/writeup.py
Docker isolation
Planned, disposable execution boundary.
- Sandbox planner · Converts theme and capability choices into a manifest.
ctf_agent/sandbox/planner.py - Sandbox manager · Builds or reuses manifest-keyed Docker images.
ctf_agent/sandbox/manager.py - Sandbox executor · Runs commands with read-only materials and disposable /tmp work.
ctf_agent/sandbox/executor.py - Sandbox image
docker/Dockerfile.sandbox - Allow-list egress proxy · Permits only declared HTTP(S) targets for web challenges.
docker/egress_proxy.py - Proxy image
docker/Dockerfile.egress-proxy
Optional systems
Not on the local solver runtime path.
- Skills hints · Provides post-classification technique hints only.
ctf_agent/skills/router.py - Skills index builder
ctf_agent/skills/build_index.py - Veria live-CTF swarm · Separate pinned CTFd integration with its own runtime.
integrations/verialabs-ctf-agent - Veria launcher
scripts/run_veria_ctf_agent.sh
Connections 23
- Automated runner → Challenge materials: inventories
- Manual solver → Solver control loop: starts
- Challenge materials → Task classifier: description + metadata
- Shared types → Task classifier: uses
- Task classifier → Sandbox planner: theme + capabilities
- Task classifier → Skills hints: post-classification hints
- Skills index builder → Skills hints: builds local index
- Sandbox planner → Sandbox manager: sandbox manifest
- Sandbox manager → Sandbox image: builds or reuses
- Sandbox manager → Sandbox executor: prepared image
- Solver control loop → Model router: bounded model turns
- Runtime settings → Model router: routes and budgets
- Solver control loop → Sandbox executor: logged commands
- Sandbox executor → Challenge materials: read-only mount
- Sandbox executor → Allow-list egress proxy: web challenge traffic
- Proxy image → Allow-list egress proxy: defines runtime
- Solver control loop → Flag extraction: candidate evidence
- Model router → Solve handoff: quota or limit replacement
- Solve handoff → Solver control loop: continuation state
- Solver control loop → Run evidence: transcript and decisions
- Flag extraction → Writeup generator: final evidence
- Writeup generator → Run evidence: generated writeup
- Veria launcher → Veria live-CTF swarm: launches separately