# yyouretoast/secagent architecture

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

- Interactive diagram: https://gitdiagram.com/yyouretoast/secagent
- Repository: https://github.com/yyouretoast/secagent

## Overview

SecAgent is a deterministic security gate for AI agents. Its main workflow accepts a dynamic agent, recorded trace, or MCP manifest through the CLI; prepares and executes scenarios or normalizes trace input; evaluates the resulting evidence against declarative OWASP policies; and emits a report for CI or local review. Separate capabilities include scenario generation, an inline SDK guardrail, telemetry/HITL capture, and a baseline-diff UI. Some relationships below rely on README statements or the SOURCE INDEX; unsampled implementation details are not assumed.

Main entry points: [`src/secagent/cli.py`](https://github.com/yyouretoast/secagent/blob/main/src/secagent/cli.py) (Scan CLI), [`src/secagent/harness/executor.py`](https://github.com/yyouretoast/secagent/blob/main/src/secagent/harness/executor.py) (Scenario executor), [`src/secagent/engine/evaluator.py`](https://github.com/yyouretoast/secagent/blob/main/src/secagent/engine/evaluator.py) (Policy engine), [`src/secagent/generator/__init__.py`](https://github.com/yyouretoast/secagent/blob/main/src/secagent/generator/__init__.py) (Scenario generator)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingest["Scan and execution"]
  node_cli["Scan CLI<br/>[cli.py]"]
  node_executor["Scenario executor<br/>[executor.py]"]
  node_runner["Agent runner<br/>[runner.py]"]
  node_discovery["Tool discovery<br/>[introspector.py]"]
  node_sandbox["Execution sandbox<br/>[sandbox.py]"]
  node_isolation["Isolated workers<br/>[isolated.py]"]
  node_mcp["MCP scanner<br/>[mcp_scanner.py]"]
  node_otlp["OTLP converter<br/>[otlp_adapter.py]"]
end

subgraph group_policy["Policy evaluation"]
  node_loader["Policy loader<br/>[loader.py]"]
  node_evaluator["Policy engine<br/>[evaluator.py]"]
  node_rules["Deterministic rules"]
  node_results["Evaluation results<br/>[models.py]"]
end

subgraph group_telemetry["Trace and guardrails"]
  node_callbacks["Trace callbacks<br/>[callbacks.py]"]
  node_hitl["HITL normalizer<br/>[hitl.py]"]
  node_redactor["PII redactor<br/>[redactor.py]"]
  node_sdk["Runtime guardrail<br/>[middleware.py]"]
end

subgraph group_outputs["Reports and review"]
  node_reporter["Audit reporter<br/>[reporter.py]"]
  node_markdown["Markdown report<br/>[markdown.py]"]
  node_ui["Baseline review UI<br/>[ui.py]"]
end

subgraph group_generation["Scenario generation"]
  node_generator["Scenario generator<br/>[__init__.py]"]
  node_fuzzer["Schema fuzzer<br/>[fuzzer.py]"]
  node_synthesis["Scenario synthesis<br/>[synthesis.py]"]
  node_cache[("Scenario cache<br/>[cache.py]")]
end

node_user(("Engineer or CI"))

node_user -->|"starts scan"| node_cli
node_cli -->|"runs scenarios"| node_executor
node_cli -->|"scans manifests"| node_mcp
node_cli -->|"loads traces"| node_otlp
node_cli -->|"evaluates evidence"| node_evaluator
node_cli -->|"generates scenarios"| node_generator
node_cli -->|"writes audit"| node_reporter
node_cli -->|"writes summary"| node_markdown
node_cli -->|"serves review"| node_ui
node_executor -->|"executes agent"| node_runner
node_runner -->|"discovers tools"| node_discovery
node_runner -->|"invokes safely"| node_sandbox
node_executor -->|"captures trace"| node_callbacks
node_executor -->|"converts trace"| node_otlp
node_executor -->|"isolates runs"| node_isolation
node_evaluator -->|"loads policies"| node_loader
node_evaluator -->|"dispatches checks"| node_rules
node_evaluator -->|"returns results"| node_results
node_loader -->|"compiles expressions"| node_rules
node_mcp -->|"checks poisoning"| node_rules
node_generator -->|"fuzzes schemas"| node_fuzzer
node_generator -->|"introspects tools"| node_discovery
node_synthesis -->|"builds scenarios"| node_generator
node_generator -->|"uses cache"| node_cache
node_callbacks -->|"scrubs trace"| node_redactor
node_hitl -->|"shares trace runtime"| node_callbacks
node_hitl -->|"scrubs approvals"| node_redactor
node_sdk -->|"checks tool calls"| node_evaluator
node_sdk -->|"records spans"| node_callbacks
node_reporter -->|"serializes findings"| node_results
node_cli -.->|"offers inline guardrail"| node_sdk

click node_cli "https://github.com/yyouretoast/secagent/blob/main/src/secagent/cli.py"
click node_executor "https://github.com/yyouretoast/secagent/blob/main/src/secagent/harness/executor.py"
click node_runner "https://github.com/yyouretoast/secagent/blob/main/src/secagent/harness/runner.py"
click node_discovery "https://github.com/yyouretoast/secagent/blob/main/src/secagent/harness/introspector.py"
click node_sandbox "https://github.com/yyouretoast/secagent/blob/main/src/secagent/harness/sandbox.py"
click node_isolation "https://github.com/yyouretoast/secagent/blob/main/src/secagent/harness/isolated.py"
click node_mcp "https://github.com/yyouretoast/secagent/blob/main/src/secagent/harness/mcp_scanner.py"
click node_otlp "https://github.com/yyouretoast/secagent/blob/main/src/secagent/telemetry/otlp_adapter.py"
click node_loader "https://github.com/yyouretoast/secagent/blob/main/src/secagent/engine/loader.py"
click node_evaluator "https://github.com/yyouretoast/secagent/blob/main/src/secagent/engine/evaluator.py"
click node_rules "https://github.com/yyouretoast/secagent/tree/main/src/secagent/engine/rules"
click node_results "https://github.com/yyouretoast/secagent/blob/main/src/secagent/engine/models.py"
click node_generator "https://github.com/yyouretoast/secagent/blob/main/src/secagent/generator/__init__.py"
click node_fuzzer "https://github.com/yyouretoast/secagent/blob/main/src/secagent/generator/fuzzer.py"
click node_synthesis "https://github.com/yyouretoast/secagent/blob/main/src/secagent/generator/synthesis.py"
click node_cache "https://github.com/yyouretoast/secagent/blob/main/src/secagent/generator/cache.py"
click node_callbacks "https://github.com/yyouretoast/secagent/blob/main/src/secagent/telemetry/callbacks.py"
click node_hitl "https://github.com/yyouretoast/secagent/blob/main/src/secagent/telemetry/hitl.py"
click node_redactor "https://github.com/yyouretoast/secagent/blob/main/src/secagent/telemetry/redactor.py"
click node_sdk "https://github.com/yyouretoast/secagent/blob/main/src/secagent/sdk/middleware.py"
click node_reporter "https://github.com/yyouretoast/secagent/blob/main/src/secagent/engine/reporter.py"
click node_markdown "https://github.com/yyouretoast/secagent/blob/main/src/secagent/reporting/markdown.py"
click node_ui "https://github.com/yyouretoast/secagent/blob/main/src/secagent/ui.py"

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_cli,node_executor,node_runner,node_discovery,node_sandbox,node_isolation,node_mcp,node_otlp toneBlue
class node_loader,node_evaluator,node_rules,node_results toneAmber
class node_callbacks,node_hitl,node_redactor,node_sdk toneMint
class node_reporter,node_markdown,node_ui toneRose
class node_generator,node_fuzzer,node_synthesis,node_cache,node_user toneIndigo
```

## Components

### Scan and execution

- [Scan CLI](https://github.com/yyouretoast/secagent/blob/main/src/secagent/cli.py): `src/secagent/cli.py`
- [Scenario executor](https://github.com/yyouretoast/secagent/blob/main/src/secagent/harness/executor.py): `src/secagent/harness/executor.py`
- [Agent runner](https://github.com/yyouretoast/secagent/blob/main/src/secagent/harness/runner.py): `src/secagent/harness/runner.py`
- [Tool discovery](https://github.com/yyouretoast/secagent/blob/main/src/secagent/harness/introspector.py): `src/secagent/harness/introspector.py`
- [Execution sandbox](https://github.com/yyouretoast/secagent/blob/main/src/secagent/harness/sandbox.py): `src/secagent/harness/sandbox.py`
- [Isolated workers](https://github.com/yyouretoast/secagent/blob/main/src/secagent/harness/isolated.py): `src/secagent/harness/isolated.py`
- [MCP scanner](https://github.com/yyouretoast/secagent/blob/main/src/secagent/harness/mcp_scanner.py): `src/secagent/harness/mcp_scanner.py`
- [OTLP converter](https://github.com/yyouretoast/secagent/blob/main/src/secagent/telemetry/otlp_adapter.py): `src/secagent/telemetry/otlp_adapter.py`

### Policy evaluation

- [Policy loader](https://github.com/yyouretoast/secagent/blob/main/src/secagent/engine/loader.py): `src/secagent/engine/loader.py`
- [Policy engine](https://github.com/yyouretoast/secagent/blob/main/src/secagent/engine/evaluator.py): `src/secagent/engine/evaluator.py`
- [Deterministic rules](https://github.com/yyouretoast/secagent/tree/main/src/secagent/engine/rules): `src/secagent/engine/rules`
- [Evaluation results](https://github.com/yyouretoast/secagent/blob/main/src/secagent/engine/models.py): `src/secagent/engine/models.py`

### Trace and guardrails

- [Trace callbacks](https://github.com/yyouretoast/secagent/blob/main/src/secagent/telemetry/callbacks.py): `src/secagent/telemetry/callbacks.py`
- [HITL normalizer](https://github.com/yyouretoast/secagent/blob/main/src/secagent/telemetry/hitl.py): `src/secagent/telemetry/hitl.py`
- [PII redactor](https://github.com/yyouretoast/secagent/blob/main/src/secagent/telemetry/redactor.py): `src/secagent/telemetry/redactor.py`
- [Runtime guardrail](https://github.com/yyouretoast/secagent/blob/main/src/secagent/sdk/middleware.py): `src/secagent/sdk/middleware.py`

### Reports and review

- [Audit reporter](https://github.com/yyouretoast/secagent/blob/main/src/secagent/engine/reporter.py): `src/secagent/engine/reporter.py`
- [Markdown report](https://github.com/yyouretoast/secagent/blob/main/src/secagent/reporting/markdown.py): `src/secagent/reporting/markdown.py`
- [Baseline review UI](https://github.com/yyouretoast/secagent/blob/main/src/secagent/ui.py): `src/secagent/ui.py`

### Scenario generation

- [Scenario generator](https://github.com/yyouretoast/secagent/blob/main/src/secagent/generator/__init__.py): `src/secagent/generator/__init__.py`
- [Schema fuzzer](https://github.com/yyouretoast/secagent/blob/main/src/secagent/generator/fuzzer.py): `src/secagent/generator/fuzzer.py`
- [Scenario synthesis](https://github.com/yyouretoast/secagent/blob/main/src/secagent/generator/synthesis.py): `src/secagent/generator/synthesis.py`
- [Scenario cache](https://github.com/yyouretoast/secagent/blob/main/src/secagent/generator/cache.py): `src/secagent/generator/cache.py`

### Other components

- **Engineer or CI**

## Connections

- Engineer or CI → Scan CLI: starts scan
- Scan CLI → Scenario executor: runs scenarios (evidence: `src/secagent/cli.py`)
- Scan CLI → MCP scanner: scans manifests (evidence: `src/secagent/cli.py`)
- Scan CLI → OTLP converter: loads traces
- Scan CLI → Policy engine: evaluates evidence (evidence: `src/secagent/cli.py`)
- Scan CLI → Scenario generator: generates scenarios (evidence: `src/secagent/cli.py`)
- Scan CLI → Audit reporter: writes audit
- Scan CLI → Markdown report: writes summary (evidence: `src/secagent/cli.py`)
- Scan CLI → Baseline review UI: serves review (evidence: `src/secagent/cli.py`)
- Scenario executor → Agent runner: executes agent (evidence: `src/secagent/harness/executor.py`)
- Agent runner → Tool discovery: discovers tools (evidence: `src/secagent/harness/runner.py`)
- Agent runner → Execution sandbox: invokes safely (evidence: `src/secagent/harness/runner.py`)
- Scenario executor → Trace callbacks: captures trace (evidence: `src/secagent/harness/executor.py`)
- Scenario executor → OTLP converter: converts trace (evidence: `src/secagent/harness/executor.py`)
- Scenario executor → Isolated workers: isolates runs (evidence: `src/secagent/harness/executor.py`)
- Policy engine → Policy loader: loads policies (evidence: `src/secagent/engine/evaluator.py`)
- Policy engine → Deterministic rules: dispatches checks (evidence: `src/secagent/engine/evaluator.py`)
- Policy engine → Evaluation results: returns results (evidence: `src/secagent/engine/evaluator.py`)
- Policy loader → Deterministic rules: compiles expressions (evidence: `src/secagent/engine/loader.py`)
- MCP scanner → Deterministic rules: checks poisoning (evidence: `src/secagent/harness/mcp_scanner.py`)
- Scenario generator → Schema fuzzer: fuzzes schemas (evidence: `src/secagent/generator/__init__.py`)
- Scenario generator → Tool discovery: introspects tools (evidence: `src/secagent/generator/__init__.py`)
- Scenario synthesis → Scenario generator: builds scenarios (evidence: `src/secagent/generator/synthesis.py`)
- Scenario generator → Scenario cache: uses cache (evidence: `src/secagent/generator/cache.py`)
- Trace callbacks → PII redactor: scrubs trace (evidence: `src/secagent/telemetry/callbacks.py`)
- HITL normalizer → Trace callbacks: shares trace runtime (evidence: `src/secagent/telemetry/hitl.py`)
- HITL normalizer → PII redactor: scrubs approvals (evidence: `src/secagent/telemetry/hitl.py`)
- Runtime guardrail → Policy engine: checks tool calls (evidence: `src/secagent/sdk/middleware.py`)
- Runtime guardrail → Trace callbacks: records spans (evidence: `src/secagent/sdk/middleware.py`)
- Audit reporter → Evaluation results: serializes findings (evidence: `src/secagent/engine/reporter.py`)
- Scan CLI → Runtime guardrail: offers inline guardrail
