How aisecuritylab/hackagent works
1. What the repo is
HackAgent is a Python 3.10+ security testing toolkit for AI agents. It is organized as a multi-module SDK plus a CLI, with a local reporting/dashboard mode and a remote cloud-sync mode.
2. Top-level execution flow
The main user path is: CLI or SDK entrypoint → attack orchestrator → attack technique implementation → target agent adapter/router → evaluator/judge → result persistence/reporting. This is the core pipeline to capture in an architecture diagram.
3. Attack subsystem
hackagent/attacks is the central engine. It contains:
- orchestrator.py for coordinating attack runs
- registry.py for attack discovery/selection
- base.py and techniques/* for concrete attack families
- generator, evaluator, and objectives layers that separate prompt generation, scoring/judging, and target objectives
Techniques include AdvPrefix, AutoDAN-Turbo, PAIR, TAP, FlipAttack, BoN, h4rm3l, CipherChat, PAP, Static Template, FC, baseline, plus RAG and indirect prompt injection variants.
4. Attack lifecycle boundaries
Each technique tends to follow the same internal contract: configuration → generation of adversarial candidates → execution against the target → evaluation/judging → metrics/results. Shared helpers under attacks/shared handle prompt parsing, response utilities, guardrails, progress reporting, translation, TUI hooks, and router creation.
5. Target-agent routing layer
hackagent/router abstracts how HackAgent talks to the target system under test. It supports provider adapters for adk, claude, and web, with discovery utilities (browser, scanner) and an envelope/dispatch layer for normalizing requests and responses. This is the boundary between HackAgent and the external AI agent framework.
6. Framework integrations
The repo is explicitly built to test agents running on Google ADK, OpenAI SDK, LiteLLM, LangChain, Claude, Ollama, web apps, and other tool-using agents. These are not separate services inside HackAgent; they are external targets reached through router/provider adapters and example harnesses.
7. Risk and threat modeling subsystem
hackagent/risks defines the security taxonomy and threat profiles. The code is split by risk category such as prompt injection, jailbreak, credential exposure, excessive agency, malicious tool invocation, misinformation, model evasion, system prompt leakage, and vector embedding weaknesses. These profiles feed the attack/objective selection model and give the system its semantic classification layer.
8. Dataset subsystem
hackagent/datasets provides benchmark inputs and custom dataset loading. It includes file-based and Hugging Face providers, intent/category helpers, preset registries, and a bundled dataset (omnisafebench). This is the data source for running standardized evaluation campaigns and custom scans.
9. CLI and interactive TUI
hackagent/cli is the human-facing control plane. It exposes commands for attacks, scanning, agents, results, config, examples, and web/dashboard access. The TUI under cli/tui renders live progress, logs, attack specs, agents, config, and results, making the CLI a real-time operations front end rather than just a thin argument parser.
10. Results, storage, and reporting
hackagent/server/storage implements persistence backends, with local and remote storage modes. The README and code structure indicate local SQLite-backed storage plus remote sync to the HackAgent platform when configured. Results flow from attack execution into storage and then into the dashboard/API.
11. Server and dashboard subsystem
hackagent/server contains the reporting web app and API surface. The api/* modules expose resources such as agents, attacks, runs, results, keys, organizations, judges, checkout, and generated chat-completions endpoints. The dashboard package builds the UI, trace analysis views, result pages, run history, and attack cards on top of those APIs.
12. Client/API boundary
hackagent/server/client.py and the generated API modules indicate a client-server boundary inside the repo: the local SDK/CLI can talk to a remote HackAgent backend, while the dashboard consumes the same API model. This separates local testing/orchestration from hosted reporting/account state.
13. Examples as integration fixtures
hackagent/examples contains runnable harnesses for different target stacks: Claude, Google ADK, LangChain RAG, LiteLLM multi-provider, Ollama, OpenAI SDK, web apps, vLLM, and indirect-prompt-injection scenarios. These are reference implementations showing how the router/attack engine attaches to real targets.
14. Testing and quality boundaries
The repository has broad unit, integration, and end-to-end coverage under tests/, mirroring the architecture: attack techniques, router/provider adapters, CLI/TUI, datasets, storage, server API, and dashboard. This suggests each subsystem is intended to be independently testable at its boundary, with integration tests validating the full attack/reporting loop.
Main entry points: orchestrator.py Orchestrator · router.py Router · commands Commands · storage Storage
Components 21
Attack Engine
Orchestrates attack runs from selection through execution and scoring.
- Orchestrator · Coordinates attack lifecycle and ties together configuration, execution, evaluation, and persistence.
hackagent/attacks/orchestrator.py - Registry · Discovers and selects attack techniques.
hackagent/attacks/registry.py - Techniques · Concrete attack implementations such as AdvPrefix, AutoDAN-Turbo, PAIR, TAP, FlipAttack, BoN, h4rm3l, CipherChat, PAP, Static Template, FC, baseline, RAG, and indirect prompt injection.
hackagent/attacks/techniques - Generator · Builds adversarial prompts and attack candidates.
hackagent/attacks/generator - Evaluator · Scores responses, applies judges, metrics, and evaluation steps.
hackagent/attacks/evaluator - Objectives · Defines attack objectives such as harmful behavior, jailbreak, policy violation, and RAG targets.
hackagent/attacks/objectives - Shared Utils · Common helpers for prompt parsing, response utilities, guardrails, progress, translation, router creation, and TUI hooks.
hackagent/attacks/shared
Target Routing
Normalizes communication with external AI agents and apps under test.
- Router · Dispatches normalized requests and responses to external target systems.
hackagent/router/router.py - Providers · Provider adapters for ADK, Claude, and web targets.
hackagent/router/providers - Discovery · Browser and scanner utilities for finding and preparing web-facing targets.
hackagent/router/discovery - Tracking · Tracks router steps, categories, context, and coordinator state.
hackagent/router/tracking
Risk & Data
Security taxonomy and benchmark inputs that shape attacks.
- Risk Profiles · Security taxonomy covering prompt injection, jailbreak, credential exposure, excessive agency, malicious tool invocation, misinformation, model evasion, system prompt leakage, and vector embedding weaknesses.
hackagent/risks - Datasets · File and Hugging Face dataset providers, presets, intents, and bundled benchmark data.
hackagent/datasets
CLI & TUI
Human control plane for running attacks and monitoring progress.
- CLI · Main command-line entrypoint for launching scans, attacks, and web access.
hackagent/cli/main.py - Commands · User-facing commands for attacks, agents, scan, results, config, examples, and web.
hackagent/cli/commands - TUI · Live terminal interface for progress, logs, attack specs, agents, config, and results.
hackagent/cli/tui
Server & Dashboard
Local/remote persistence, API surface, and reporting UI.
- Storage · Local and remote storage backends for results and run state.
hackagent/server/storage - API · Generated server API resources for agents, attacks, runs, results, keys, organizations, judges, checkout, and chat completions.
hackagent/server/api - Dashboard · Reporting UI for traces, runs, results, attack cards, and analysis views.
hackagent/server/dashboard - Client · SDK-side client for talking to a remote HackAgent backend.
hackagent/server/client.py
Examples
Runnable integration fixtures showing supported target stacks.
- Examples · Runnable harnesses for Claude, Google ADK, LangChain RAG, LiteLLM, Ollama, OpenAI SDK, vLLM, and web targets.
hackagent/examples
Connections 23
- CLI → Commands: invokes · The CLI entrypoint dispatches to subcommands.
- Commands → Orchestrator: starts · Attack and scan commands launch the orchestrated run pipeline.
- Commands → TUI: renders · Interactive commands surface live progress and results in the TUI.
- Orchestrator → Registry: selects · The orchestrator resolves which technique to run.
- Registry → Techniques: loads · Registered attack families are instantiated from the technique set.
- Orchestrator → Generator: drives · Orchestration triggers prompt/candidate generation.
- Generator → Shared Utils: uses · Generation relies on shared parsing, translation, and utilities.
- Orchestrator → Router: targets · Generated attacks are executed against the target boundary.
- Router → Providers: adapts · Router dispatches through provider-specific adapters.
- Router → Discovery: discovers · Discovery utilities assist with finding and preparing targets.
- Router → Tracking: records · Router activity is tracked for analysis and debugging.
- Orchestrator → Objectives: selects goals · Attack runs are parameterized by objectives and threat models.
- Orchestrator → Evaluator: scores · Executed runs are judged and scored.
- Evaluator → Shared Utils: reuses · Evaluation shares helpers for response handling and progress.
- Risk Profiles → Objectives: classifies · Risk profiles supply the semantic taxonomy for attack objectives.
- Datasets → Orchestrator: feeds · Datasets provide inputs for standardized and custom runs.
- Orchestrator → Storage: persists · Run outputs and results are written to storage backends.
- Storage → Dashboard: serves · Stored data powers reporting and history views.
- API → Storage: reads/writes · API resources operate over persisted runs and results.
- Client → API: calls · Local SDK and CLI clients talk to the remote backend API.
- Dashboard → API: consumes · The dashboard is built on top of the API surface.
- Examples → Router: integrates · Examples demonstrate how attacks attach to target stacks through the router.
- Examples → Orchestrator: demonstrates · Example scripts exercise the attack execution pipeline.