# aisecuritylab/hackagent architecture

> Architecture diagram of the GitHub repository aisecuritylab/hackagent, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/aisecuritylab/hackagent
- Repository: https://github.com/aisecuritylab/hackagent

## Overview

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: [`hackagent/attacks/orchestrator.py`](https://github.com/aisecuritylab/hackagent/blob/main/hackagent/attacks/orchestrator.py) (Orchestrator), [`hackagent/router/router.py`](https://github.com/aisecuritylab/hackagent/blob/main/hackagent/router/router.py) (Router), [`hackagent/cli/commands`](https://github.com/aisecuritylab/hackagent/tree/main/hackagent/cli/commands) (Commands), [`hackagent/server/storage`](https://github.com/aisecuritylab/hackagent/tree/main/hackagent/server/storage) (Storage)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_grp_core["Attack Engine"]
  node_node_orchestrator["Orchestrator<br/>run coordinator<br/>[orchestrator.py]"]
  node_node_registry["Registry<br/>attack catalog<br/>[registry.py]"]
  node_node_techniques["Techniques<br/>attack families"]
  node_node_generator["Generator<br/>candidate builder"]
  node_node_evaluator["Evaluator<br/>judge layer"]
  node_node_objectives["Objectives<br/>goal models"]
  node_node_shared["Shared Utils<br/>attack helpers"]
end

subgraph group_grp_target["Target Routing"]
  node_node_router["Router<br/>target boundary<br/>[router.py]"]
  node_node_providers["Providers<br/>adapters"]
  node_node_discovery["Discovery<br/>target scan"]
  node_node_tracking["Tracking<br/>telemetry"]
end

subgraph group_grp_risk_data["Risk & Data"]
  node_node_risks["Risk Profiles<br/>taxonomy"]
  node_node_datasets["Datasets<br/>benchmarks"]
end

subgraph group_grp_cli["CLI & TUI"]
  node_node_cli_main["CLI<br/>command entrypoint<br/>[main.py]"]
  node_node_cli_commands["Commands"]
  node_node_cli_tui["TUI<br/>interactive view"]
end

subgraph group_grp_server["Server & Dashboard"]
  node_node_storage[("Storage<br/>persistence")]
  node_node_api["API<br/>backend surface"]
  node_node_dashboard["Dashboard<br/>web UI"]
  node_node_client["Client<br/>[client.py]"]
end

subgraph group_grp_examples["Examples"]
  node_node_examples["Examples<br/>integration fixtures"]
end

node_node_cli_main -->|"invokes"| node_node_cli_commands
node_node_cli_commands -->|"starts"| node_node_orchestrator
node_node_cli_commands -->|"renders"| node_node_cli_tui
node_node_orchestrator -->|"selects"| node_node_registry
node_node_registry -->|"loads"| node_node_techniques
node_node_orchestrator -->|"drives"| node_node_generator
node_node_generator -->|"uses"| node_node_shared
node_node_orchestrator -->|"targets"| node_node_router
node_node_router -->|"adapts"| node_node_providers
node_node_router -->|"discovers"| node_node_discovery
node_node_router -->|"records"| node_node_tracking
node_node_orchestrator -->|"selects goals"| node_node_objectives
node_node_orchestrator -->|"scores"| node_node_evaluator
node_node_evaluator -->|"reuses"| node_node_shared
node_node_risks -->|"classifies"| node_node_objectives
node_node_datasets -->|"feeds"| node_node_orchestrator
node_node_orchestrator -->|"persists"| node_node_storage
node_node_storage -->|"serves"| node_node_dashboard
node_node_api -->|"reads/writes"| node_node_storage
node_node_client -->|"calls"| node_node_api
node_node_dashboard -->|"consumes"| node_node_api
node_node_examples -->|"integrates"| node_node_router
node_node_examples -->|"demonstrates"| node_node_orchestrator

click node_node_cli_main "https://github.com/aisecuritylab/hackagent/blob/main/hackagent/cli/main.py"
click node_node_cli_commands "https://github.com/aisecuritylab/hackagent/tree/main/hackagent/cli/commands"
click node_node_cli_tui "https://github.com/aisecuritylab/hackagent/tree/main/hackagent/cli/tui"
click node_node_orchestrator "https://github.com/aisecuritylab/hackagent/blob/main/hackagent/attacks/orchestrator.py"
click node_node_registry "https://github.com/aisecuritylab/hackagent/blob/main/hackagent/attacks/registry.py"
click node_node_techniques "https://github.com/aisecuritylab/hackagent/tree/main/hackagent/attacks/techniques"
click node_node_generator "https://github.com/aisecuritylab/hackagent/tree/main/hackagent/attacks/generator"
click node_node_evaluator "https://github.com/aisecuritylab/hackagent/tree/main/hackagent/attacks/evaluator"
click node_node_objectives "https://github.com/aisecuritylab/hackagent/tree/main/hackagent/attacks/objectives"
click node_node_shared "https://github.com/aisecuritylab/hackagent/tree/main/hackagent/attacks/shared"
click node_node_router "https://github.com/aisecuritylab/hackagent/blob/main/hackagent/router/router.py"
click node_node_providers "https://github.com/aisecuritylab/hackagent/tree/main/hackagent/router/providers"
click node_node_discovery "https://github.com/aisecuritylab/hackagent/tree/main/hackagent/router/discovery"
click node_node_tracking "https://github.com/aisecuritylab/hackagent/tree/main/hackagent/router/tracking"
click node_node_risks "https://github.com/aisecuritylab/hackagent/tree/main/hackagent/risks"
click node_node_datasets "https://github.com/aisecuritylab/hackagent/tree/main/hackagent/datasets"
click node_node_storage "https://github.com/aisecuritylab/hackagent/tree/main/hackagent/server/storage"
click node_node_api "https://github.com/aisecuritylab/hackagent/tree/main/hackagent/server/api"
click node_node_dashboard "https://github.com/aisecuritylab/hackagent/tree/main/hackagent/server/dashboard"
click node_node_client "https://github.com/aisecuritylab/hackagent/blob/main/hackagent/server/client.py"
click node_node_examples "https://github.com/aisecuritylab/hackagent/tree/main/hackagent/examples"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_node_orchestrator,node_node_registry,node_node_techniques,node_node_generator,node_node_evaluator,node_node_objectives,node_node_shared toneBlue
class node_node_router,node_node_providers,node_node_discovery,node_node_tracking toneAmber
class node_node_risks,node_node_datasets toneMint
class node_node_cli_main,node_node_cli_commands,node_node_cli_tui toneRose
class node_node_storage,node_node_api,node_node_dashboard,node_node_client toneIndigo
class node_node_examples toneTeal
```

## Components

### Attack Engine

Orchestrates attack runs from selection through execution and scoring.

- [Orchestrator](https://github.com/aisecuritylab/hackagent/blob/main/hackagent/attacks/orchestrator.py): run coordinator · Coordinates attack lifecycle and ties together configuration, execution, evaluation, and persistence. · `hackagent/attacks/orchestrator.py`
- [Registry](https://github.com/aisecuritylab/hackagent/blob/main/hackagent/attacks/registry.py): attack catalog · Discovers and selects attack techniques. · `hackagent/attacks/registry.py`
- [Techniques](https://github.com/aisecuritylab/hackagent/tree/main/hackagent/attacks/techniques): attack families · 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](https://github.com/aisecuritylab/hackagent/tree/main/hackagent/attacks/generator): candidate builder · Builds adversarial prompts and attack candidates. · `hackagent/attacks/generator`
- [Evaluator](https://github.com/aisecuritylab/hackagent/tree/main/hackagent/attacks/evaluator): judge layer · Scores responses, applies judges, metrics, and evaluation steps. · `hackagent/attacks/evaluator`
- [Objectives](https://github.com/aisecuritylab/hackagent/tree/main/hackagent/attacks/objectives): goal models · Defines attack objectives such as harmful behavior, jailbreak, policy violation, and RAG targets. · `hackagent/attacks/objectives`
- [Shared Utils](https://github.com/aisecuritylab/hackagent/tree/main/hackagent/attacks/shared): attack helpers · 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](https://github.com/aisecuritylab/hackagent/blob/main/hackagent/router/router.py): target boundary · Dispatches normalized requests and responses to external target systems. · `hackagent/router/router.py`
- [Providers](https://github.com/aisecuritylab/hackagent/tree/main/hackagent/router/providers): adapters · Provider adapters for ADK, Claude, and web targets. · `hackagent/router/providers`
- [Discovery](https://github.com/aisecuritylab/hackagent/tree/main/hackagent/router/discovery): target scan · Browser and scanner utilities for finding and preparing web-facing targets. · `hackagent/router/discovery`
- [Tracking](https://github.com/aisecuritylab/hackagent/tree/main/hackagent/router/tracking): telemetry · Tracks router steps, categories, context, and coordinator state. · `hackagent/router/tracking`

### Risk & Data

Security taxonomy and benchmark inputs that shape attacks.

- [Risk Profiles](https://github.com/aisecuritylab/hackagent/tree/main/hackagent/risks): taxonomy · 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](https://github.com/aisecuritylab/hackagent/tree/main/hackagent/datasets): benchmarks · 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](https://github.com/aisecuritylab/hackagent/blob/main/hackagent/cli/main.py): command entrypoint · Main command-line entrypoint for launching scans, attacks, and web access. · `hackagent/cli/main.py`
- [Commands](https://github.com/aisecuritylab/hackagent/tree/main/hackagent/cli/commands): subcommands · User-facing commands for attacks, agents, scan, results, config, examples, and web. · `hackagent/cli/commands`
- [TUI](https://github.com/aisecuritylab/hackagent/tree/main/hackagent/cli/tui): interactive view · 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](https://github.com/aisecuritylab/hackagent/tree/main/hackagent/server/storage): persistence · Local and remote storage backends for results and run state. · `hackagent/server/storage`
- [API](https://github.com/aisecuritylab/hackagent/tree/main/hackagent/server/api): backend surface · Generated server API resources for agents, attacks, runs, results, keys, organizations, judges, checkout, and chat completions. · `hackagent/server/api`
- [Dashboard](https://github.com/aisecuritylab/hackagent/tree/main/hackagent/server/dashboard): web UI · Reporting UI for traces, runs, results, attack cards, and analysis views. · `hackagent/server/dashboard`
- [Client](https://github.com/aisecuritylab/hackagent/blob/main/hackagent/server/client.py): api client · SDK-side client for talking to a remote HackAgent backend. · `hackagent/server/client.py`

### Examples

Runnable integration fixtures showing supported target stacks.

- [Examples](https://github.com/aisecuritylab/hackagent/tree/main/hackagent/examples): integration fixtures · Runnable harnesses for Claude, Google ADK, LangChain RAG, LiteLLM, Ollama, OpenAI SDK, vLLM, and web targets. · `hackagent/examples`

## Connections

- 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.
