# berylliumsec/nebula

> Local-first security workbench whose chat agents and LangGraph missions run tools through a deterministic scope, DNS and approval policy.

- Category: [Open-source AI pentest and offensive-security agents](https://llms-technical-reviews.com/offensive-security-agents/)
- Repository: https://github.com/berylliumsec/nebula (reviewed at commit `7332d9a05127933d2cc649e6797c9586466cfa8a`, 2026-11-02)
- Stars: 1134 · Language: Python · License: BSD-2-Clause
- Canonical page: https://llms-technical-reviews.com/p/nebula/

## Overview

Nebula 3 (`3.0.0-beta.3`) is an operator workbench, not a fire-and-forget scanner. A Python "Core" process (FastAPI, about 190k lines under `src/nebula/v3`) runs behind a Tauri desktop app. A Project holds the scope, a Kali automation container or host shell, a security browser with interception, notes, findings and reports. Work happens in two ways:

- **Chat assistants.** A model or a vendor harness (Codex App Server, Grok ACP) talks with the operator and calls tools. "Butler" is a supervising assistant that can watch, steer and delegate to them.
- **Missions.** These are durable LangGraph runs (plan, dispatch, approval, verify, synthesize) with run budgets.

Both paths call tools through the same `ToolBroker`. The broker validates arguments, resolves DNS, and asks a deterministic `PolicyEngine` whether the call is allowed, denied or needs operator approval. No model decides whether an action is safe. That shared broker, a deny-by-default container network, and approvals that survive restarts make Nebula the most carefully engineered control plane in this category. The large exception is Host mode, covered below.

## Architecture

```mermaid
flowchart LR
  UI["Tauri desktop / browser UI"] --> API["Core API (FastAPI)"]
  API --> CHAT["Chat assistants + Butler"]
  API --> MIS["MissionRuntime (LangGraph)"]
  CHAT --> BRK["ToolBroker"]
  MIS --> BRK
  BRK --> POL["PolicyEngine"]
  BRK --> LED["Tool ledger + approvals"]
  BRK --> AUTO["Automation runtime"]
  AUTO --> DOCK["Kali container + egress helper"]
  AUTO --> HOST["Host bash (Host mode)"]
  BRK --> MCP["MCP gateway / browser tools"]
  LED --> DB["SQL store + artifacts"]
  MIS --> CKPT["SQLite checkpoints"]
  CHAT --> MEM["Butler memory + Chroma"]
```

| Component | Path | Role |
|---|---|---|
| Core API / CLI | `src/nebula/v3/api.py`, `cli.py` | `nebula-core serve` (loopback + bearer token), `run`, `migrate`, import/export |
| Chat | `src/nebula/v3/chat*.py`, `harnesses.py` | Provider tool loops, planning phase, subagents, Codex/Grok harness bridging |
| Missions | `src/nebula/v3/orchestration.py`, `missions.py` | LangGraph control plane, budgets, recovery |
| Specialists | `src/nebula/v3/agent_tooling.py` | `BrokeredToolSpecialist` (one routed tool turn per step), deterministic `ToolMissionSupervisor` |
| Broker | `src/nebula/v3/tools.py` | `ToolSpec` contract, ledger reservation, canonicalisation, policy decision, approval |
| Policy | `src/nebula/v3/policy.py` | Time window, prohibitions, target/port/URL scope, DNS pinning, risk-class approval |
| Execution | `src/nebula/v3/automation_runtime.py`, `sandbox.py`, `egress_helper.py` | Docker/Podman or Host sessions; deny-by-default egress namespace with a policy DNS resolver |
| Evidence and reports | `evidence.py`, `artifacts.py`, `reporting.py` | Hashed artifacts, finding lifecycle, deterministic PDF render |
| Memory | `context.py`, `butler_memory.py` | Context compaction snapshots; Butler's SQLite memory with a rebuildable Chroma index |

## How a request flows

Take an executable Mission that runs `nmap` against an in-scope host:

1. **Plan.** `MissionRuntime` compiles a `StateGraph` with `plan`, `dispatch`, `approval`, `verify`, `fail` and `synthesize` nodes and a checkpointer ([orchestration.py](https://github.com/berylliumsec/nebula/blob/7332d9a05127933d2cc649e6797c9586466cfa8a/src/nebula/v3/orchestration.py#L511-L556)). For tool missions, the supervisor is deterministic. `ToolMissionSupervisor` groups the tools the operator selected into roles, or follows operator-written stages ([agent_tooling.py](https://github.com/berylliumsec/nebula/blob/7332d9a05127933d2cc649e6797c9586466cfa8a/src/nebula/v3/agent_tooling.py#L136-L200)). The model does not write the plan.
2. **Dispatch.** Each task goes to a `BrokeredToolSpecialist` that only sees the tools of its role ([agent_tooling.py](https://github.com/berylliumsec/nebula/blob/7332d9a05127933d2cc649e6797c9586466cfa8a/src/nebula/v3/agent_tooling.py#L259-L295)). Each turn, the model either calls a tool or calls `nebula.finish_task`. Three turns in a row with no action end the task as blocked ([agent_tooling.py](https://github.com/berylliumsec/nebula/blob/7332d9a05127933d2cc649e6797c9586466cfa8a/src/nebula/v3/agent_tooling.py#L74-L93)). The model's routing response is journaled before any call runs, so a restart replays it instead of asking again ([orchestration.py](https://github.com/berylliumsec/nebula/blob/7332d9a05127933d2cc649e6797c9586466cfa8a/src/nebula/v3/orchestration.py#L271-L316)).
3. **Broker.** `ToolBroker.prepare` reserves a ledger row, validates the JSON schema, canonicalises the target (including DNS resolution), and calls `PolicyEngine.evaluate`. A tool contract can also force approval ([tools.py](https://github.com/berylliumsec/nebula/blob/7332d9a05127933d2cc649e6797c9586466cfa8a/src/nebula/v3/tools.py#L1805-L1950)).
4. **Policy.** The engine checks the scope's time window, prohibited actions and `local_only` rule. For network-capable tools, it requires a provable target inside the allowed CIDRs, domains or URLs and allowed ports. Every resolved address must also be authorised, which blocks DNS rebinding. Credential use, exploitation, persistence, destructive and scope-change risk classes always need approval ([policy.py](https://github.com/berylliumsec/nebula/blob/7332d9a05127933d2cc649e6797c9586466cfa8a/src/nebula/v3/policy.py#L194-L300), [L302-L370](https://github.com/berylliumsec/nebula/blob/7332d9a05127933d2cc649e6797c9586466cfa8a/src/nebula/v3/policy.py#L302-L370)).
5. **Approve.** A pending approval routes the graph to `approval`, which calls LangGraph `interrupt()`. The run waits, with its checkpoint saved, until the operator approves, edits or rejects ([orchestration.py](https://github.com/berylliumsec/nebula/blob/7332d9a05127933d2cc649e6797c9586466cfa8a/src/nebula/v3/orchestration.py#L1961-L1980), [L636-L659](https://github.com/berylliumsec/nebula/blob/7332d9a05127933d2cc649e6797c9586466cfa8a/src/nebula/v3/orchestration.py#L636-L659)).
6. **Verify and finish.** After dispatch, the graph routes to `verify` while results are unchecked, to `fail` on any failed or blocked task, and to `synthesize` when all tasks are complete ([orchestration.py](https://github.com/berylliumsec/nebula/blob/7332d9a05127933d2cc649e6797c9586466cfa8a/src/nebula/v3/orchestration.py#L1832-L1849)). Duration, token, cost and tool-call budgets are checked on every dispatch ([orchestration.py](https://github.com/berylliumsec/nebula/blob/7332d9a05127933d2cc649e6797c9586466cfa8a/src/nebula/v3/orchestration.py#L2266-L2289)).

## Key components

### Tool contract and risk classes

Every capability is a `ToolSpec` that declares `risk_class`, `network_access`, `target_argument`/`port_argument`, filesystem access, credential classes, timeout and parser ([tools.py](https://github.com/berylliumsec/nebula/blob/7332d9a05127933d2cc649e6797c9586466cfa8a/src/nebula/v3/tools.py#L281-L316)). The nine risk classes range from `local_read` to `scope_change` ([domain.py](https://github.com/berylliumsec/nebula/blob/7332d9a05127933d2cc649e6797c9586466cfa8a/src/nebula/v3/domain.py#L243-L252)). A network tool that cannot name its destination is denied unless the scope allows all targets. This is stricter than anything else in this category.

### Execution runtimes

The general primitive is `run_command`: Bash in a session-scoped, pinned Kali container. Its network mode is `none` by default, or `project_scope` on request. The spec is classed `workspace_write` whatever the command does ([automation_tools.py](https://github.com/berylliumsec/nebula/blob/7332d9a05127933d2cc649e6797c9586466cfa8a/src/nebula/v3/automation_tools.py#L96-L131)). In Docker mode, scope is enforced at the network layer:

- The scope's CIDRs and ports become egress allow rules, and its domains go to a policy-aware DNS resolver inside a deny-by-default namespace ([automation_runtime.py](https://github.com/berylliumsec/nebula/blob/7332d9a05127933d2cc649e6797c9586466cfa8a/src/nebula/v3/automation_runtime.py#L2223-L2273), [egress_helper.py](https://github.com/berylliumsec/nebula/blob/7332d9a05127933d2cc649e6797c9586466cfa8a/src/nebula/v3/egress_helper.py#L1-L2)).
- Sessions start with no egress. The default `on_boundary` approval policy asks the operator the first time a command requests `project_scope` ([automation_runtime.py](https://github.com/berylliumsec/nebula/blob/7332d9a05127933d2cc649e6797c9586466cfa8a/src/nebula/v3/automation_runtime.py#L1441-L1497)).
- Sandbox requests default to a non-root user and a read-only root filesystem ([sandbox.py](https://github.com/berylliumsec/nebula/blob/7332d9a05127933d2cc649e6797c9586466cfa8a/src/nebula/v3/sandbox.py#L269-L299)).

### Host mode and the bypass switches

New Projects are created with `execution_mode="host"`. Host mode cannot be used until the operator acknowledges host access ([setup.py](https://github.com/berylliumsec/nebula/blob/7332d9a05127933d2cc649e6797c9586466cfa8a/src/nebula/v3/setup.py#L280-L319)). Once it is acknowledged, `run_command` is rewritten to run Bash "directly on the Nebula host as Core's OS user" with host networking ([automation_tools.py](https://github.com/berylliumsec/nebula/blob/7332d9a05127933d2cc649e6797c9586466cfa8a/src/nebula/v3/automation_tools.py#L340-L367)). Three things follow:

- Commands are not checked against scope. Only the time window is checked.
- The default `on_boundary` policy never asks for approval, because the network mode is forced to `host`. Only the `always` policy gates each command ([automation_runtime.py](https://github.com/berylliumsec/nebula/blob/7332d9a05127933d2cc649e6797c9586466cfa8a/src/nebula/v3/automation_runtime.py#L1441-L1497), [L2240-L2263](https://github.com/berylliumsec/nebula/blob/7332d9a05127933d2cc649e6797c9586466cfa8a/src/nebula/v3/automation_runtime.py#L2240-L2263)).
- Scope still governs the tools that name their target, such as browser navigation and target-aware tools.

Two scope flags widen access further. `allow_all_targets` opens egress to everything. `bypass_permissions` makes `PolicyEngine.evaluate` return ALLOW for everything and skips command approvals ([domain.py](https://github.com/berylliumsec/nebula/blob/7332d9a05127933d2cc649e6797c9586466cfa8a/src/nebula/v3/domain.py#L728-L761)). Both are opt-in.

### Findings, evidence and reports

Findings move from `candidate` to `validated` or `confirmed`, and can also be marked false-positive, accepted-risk, remediated or retest ([domain.py](https://github.com/berylliumsec/nebula/blob/7332d9a05127933d2cc649e6797c9586466cfa8a/src/nebula/v3/domain.py#L372-L381)). In missions, `EvidenceVerifier` rejects any result that proposes candidate findings without linked evidence IDs or reproducible steps ([orchestration.py](https://github.com/berylliumsec/nebula/blob/7332d9a05127933d2cc649e6797c9586466cfa8a/src/nebula/v3/orchestration.py#L341-L363)). This is a deterministic completeness check. It does not re-run the proof. Reports can only become `final` with an operator sign-off ([domain.py](https://github.com/berylliumsec/nebula/blob/7332d9a05127933d2cc649e6797c9586466cfa8a/src/nebula/v3/domain.py#L5273-L5299)). The PDF renderer is deterministic, uses bundled fonts, and hashes every referenced artifact ([reporting.py](https://github.com/berylliumsec/nebula/blob/7332d9a05127933d2cc649e6797c9586466cfa8a/src/nebula/v3/reporting.py#L87-L130)).

### State and models

All entities (runs, tool calls, approvals, findings, evidence) live in a SQLAlchemy store, with optimistic revision checks. Missions also checkpoint into SQLite with `durability="sync"`, can be recovered after a Core restart, and delete their checkpoints when they finish. Chat context is compacted into immutable snapshots, with a working ceiling of 200k input tokens and a 75% target ([context.py](https://github.com/berylliumsec/nebula/blob/7332d9a05127933d2cc649e6797c9586466cfa8a/src/nebula/v3/context.py#L54-L82)). Butler memory is a separate authoritative SQLite file with a rebuildable Chroma index ([butler_memory.py](https://github.com/berylliumsec/nebula/blob/7332d9a05127933d2cc649e6797c9586466cfa8a/src/nebula/v3/butler_memory.py#L1-L6)). `ProviderFlavor` lists 25 provider kinds, including `custom`, from OpenAI and Anthropic to Ollama, vLLM and llama.cpp ([providers.py](https://github.com/berylliumsec/nebula/blob/7332d9a05127933d2cc649e6797c9586466cfa8a/src/nebula/v3/providers.py#L196-L222)). Mission budgets default to unbounded. The API rejects requests above 200k tokens, $100 or 100 tool calls ([missions.py](https://github.com/berylliumsec/nebula/blob/7332d9a05127933d2cc649e6797c9586466cfa8a/src/nebula/v3/missions.py#L2009-L2045)).

## Extending it

- **MCP servers:** each server gets a profile with an approval mode (`risk_based`, `allow`, `ask`, `deny`). Harness tool calls are re-evaluated by `PolicyEngine` before they run ([harnesses.py](https://github.com/berylliumsec/nebula/blob/7332d9a05127933d2cc649e6797c9586466cfa8a/src/nebula/v3/harnesses.py#L17570-L17610)).
- **Skills and hooks:** Projects accept `SKILL.md` skills and operator hooks for assistant work.
- **SSH environments:** enabled hosts become `ssh.<host>.run_command` tools on the same policy and ledger path.
- **New fixed tools:** define a `ToolSpec` with an honest risk class and target argument, and give it a role prefix in `_ROLE_BY_PREFIX` if missions should use it.

## Running it

Install the Linux preview from the signed APT repository, a DEB or the AppImage, or build from source with Poetry, Node 20, Rust and Tauri (`npm --prefix ui run dev:desktop`). `nebula-core serve` binds `127.0.0.1` by default, generates a bearer token if none is given, and needs `--allow-remote` to bind elsewhere ([cli.py](https://github.com/berylliumsec/nebula/blob/7332d9a05127933d2cc649e6797c9586466cfa8a/src/nebula/v3/cli.py#L370-L400)). Docker or Podman is needed for Kali containers. A model provider or a Codex/Grok harness is needed for agent work.

## Strengths and caveats

- **Strength: one deterministic policy path.** Scope, ports, DNS pinning, time windows, prohibitions and risk-class approvals sit in a small, readable `PolicyEngine`, shared by chats, missions, harnesses and MCP.
- **Strength: real network containment in Docker mode.** Egress is deny-by-default, DNS is policy-aware, the container runs non-root on a read-only filesystem, and egress is approved on first use.
- **Strength: durability.** Ledgered tool calls, journaled routing responses and checkpointed approvals mean a crash neither repeats nor loses an action.
- **Caveat: Host mode is the default runtime and is unscoped for shell.** After acknowledgement, `run_command` has the host's full network and filesystem, and the default approval policy does not gate it.
- **Caveat: missions are thin on autonomy.** Plans come from operator-selected tools or stages, and verification checks that evidence exists, not that the finding is true.
- **Caveat: size.** About 190k lines of Python plus a Tauri app is a lot to audit and run for one operator, and the product is still a beta.

*Sources: code at 7332d9a, verified Q&A.*

## How berylliumsec/nebula answers the Open-source AI pentest and offensive-security agents questions

### How is the agent loop and planning implemented? (answered)

Nebula uses a **single supervisor/multiple-specialist** architecture built on LangGraph's StateGraph (`orchestration.py:511-556`). A `MissionRuntime` compiles a graph with five nodes — **plan → dispatch → approval → verify → synthesize** — with a conditional edge from dispatch that loops back to dispatch until every task is terminal, then routes to fail/verify/synthesize/approval (`orchestration.py:541-555`, `orchestration.py:1832-1848`).

The **supervisor** (the `Supervisor` protocol at `orchestration.py:245-256`) is a model-backed or static agent that produces a `MissionPlan` containing a DAG of `PlannedTask` objects, each assigned one of eight `SpecialistRole` values: `SCOPE_PLANNING`, `PASSIVE_RECON`, `NETWORK_SERVICE`, `WEB_API`, `VULNERABILITY_INTELLIGENCE`, `CODE_ANALYSIS`, `EVIDENCE_VERIFICATION`, `REPORTING_REMEDIATION` (`orchestration.py:107-116`). Tasks declare `depends_on` dependencies, and the plan validates acyclicity (`orchestration.py:139-172`).

The **specialists** (`BrokeredToolSpecialist` in `agent_tooling.py:259-295`) execute one tool call per model turn. Each specialist is bound to a `SpecialistRole` and sees only its own subset of tools (derived from a `role_for_tool()` prefix map at `agent_tooling.py:74-86`). Turn structure: the model receives the task objective, allowed tools, and prior results; it either calls a tool or calls `nebula.finish_task` (`agent_tooling.py:87-88, 343-346, 776-900`). Finish requires `status` (complete/blocked), `summary`, and `rationale`; it aggregates evidence IDs, reproducible steps, and candidate findings from the specialist's prior turns.

Stop conditions: the model may loop indefinitely within one task until it calls `finish_task`, or hit `_MAX_CONSECUTIVE_ROUTING_DEVIATIONS` (3) empty routing responses (`agent_tooling.py:93`). A `RunBudget` caps max tokens, cost, duration, tool calls, delegation depth (default 3), and retries (default 2) (`domain.py:2560-2569`). Missions enforce budgets at dispatch (`orchestration.py:805-807` throws `BudgetExceeded`). The API layer also sets `MAX_API_MISSION_TOKENS=200K`, `MAX_API_MISSION_COST_USD=100`, and `MAX_API_MISSION_RETRIES=2` (`missions.py:60-64`).

The graph's `_approval` node (`orchestration.py:1961-1980`) pauses the entire mission via LangGraph's `interrupt()` when a tool call requires operator approval; the run enters `WAITING_APPROVAL` status and can be resumed with the approval response (`orchestration.py:639` resume method via `Command(resume=response)`).

> **Editor's note.** Correction: mission planning is deterministic, not model-backed. ToolMissionSupervisor builds the task graph from the operator-selected tools or stages, and the model only drives each specialist's tool turns. The 200K-token / $100 API constants are ceilings on requested budgets; RunBudget caps default to unbounded.

Citations: [src/nebula/v3/orchestration.py:511-556](https://github.com/berylliumsec/nebula/blob/7332d9a05127933d2cc649e6797c9586466cfa8a/src/nebula/v3/orchestration.py#L511-L556) · [src/nebula/v3/orchestration.py:107-116](https://github.com/berylliumsec/nebula/blob/7332d9a05127933d2cc649e6797c9586466cfa8a/src/nebula/v3/orchestration.py#L107-L116) · [src/nebula/v3/orchestration.py:139-172](https://github.com/berylliumsec/nebula/blob/7332d9a05127933d2cc649e6797c9586466cfa8a/src/nebula/v3/orchestration.py#L139-L172) · [src/nebula/v3/orchestration.py:1832-1848](https://github.com/berylliumsec/nebula/blob/7332d9a05127933d2cc649e6797c9586466cfa8a/src/nebula/v3/orchestration.py#L1832-L1848) · [src/nebula/v3/agent_tooling.py:86-93](https://github.com/berylliumsec/nebula/blob/7332d9a05127933d2cc649e6797c9586466cfa8a/src/nebula/v3/agent_tooling.py#L86-L93) · [src/nebula/v3/agent_tooling.py:259-295](https://github.com/berylliumsec/nebula/blob/7332d9a05127933d2cc649e6797c9586466cfa8a/src/nebula/v3/agent_tooling.py#L259-L295)

### How are security tools integrated and executed? (answered)

Tools are integrated through a **three-layer architecture**: `ToolSpec` definitions, a `ToolBroker` execution engine, and a `SandboxRunner` for container isolation.

**Core shell commands** (`automation_tools.py:78-163`) expose `run_command` and `process_io` as typed `ToolSpec` objects. Each spec declares a `risk_class`, `input_schema` (JSON Schema), `filesystem_access`, `network_access`, `target_argument`, `timeout_seconds`, and a `parser` contract (`tools.py:281-394`). The `run_command` tool accepts a command string, working directory, timeout, background flag, and network mode (`none` or `project_scope`); on host execution mode it also provides `host` networking (`automation_tools.py:354-367`).

**Container sandbox** (`sandbox.py:270-299`): `SandboxRequest` specifies the image, command, workspace path, network mode (`NONE`, `SCOPED`, `VPN`, `UNRESTRICTED`), egress rules (IP+port whitelist at `sandbox.py:80-112`), user namespace (`NON_ROOT` by default), read-only root filesystem, CPU/memory/timeout limits. `ContainerSandboxRunner.run` (`sandbox.py:1885`) builds a `docker/podman run` command from these parameters. If no container runtime is configured, `AnalysisOnlyRunner.run` (`sandbox.py:1027-1032`) throws `SandboxUnavailable` — there is **no host fallback**.

**MCP servers** (`mcp.py:1-80`) are connected through a gateway shim using stdio or Streamable HTTP transport, each with its own `McpServerProfile` (approval mode, auth mode, CWD policy).

**Tool-to-role mapping** (`agent_tooling.py:74-86`): `run_command`/`process_io` → `NETWORK_SERVICE`, `nmap.*` → `NETWORK_SERVICE`, `nuclei.*` → `WEB_API`, `searchsploit.*` → `VULNERABILITY_INTELLIGENCE`, `semgrep.*` → `CODE_ANALYSIS`, `browser.*` → `NETWORK_SERVICE`.

**SSH environments** (`environments.py:1-80`) create one `ssh.<host>.run_command` tool per enabled SSH host, sharing the same policy/approval/ledger path as container tools.

**Security browser** (`agent_security_tools.py:60-80`) provides an MCP surface for the agent to proxy requests through, intercept traffic, replay requests, and launch assessments — all scoped to the engagement.

**Web search** (`web_search.py:1-40`) runs through a pinned SearXNG loopback container — it's research, not recon: no tool can navigate to a result URL without passing scope checks.

**The ToolBroker** (`tools.py:1756-1777`) orchestrates everything: it holds the `ToolRegistry`, `PolicyEngine`, `SandboxRunner`, `ToolLedger`, `DNS resolver`, and `evidence_recorder`. Every invocation is resolved against policy before execution and its output is captured as a `ToolResultReceipt` with timing, evidence IDs, and artifact references.


Citations: [src/nebula/v3/automation_tools.py:78-163](https://github.com/berylliumsec/nebula/blob/7332d9a05127933d2cc649e6797c9586466cfa8a/src/nebula/v3/automation_tools.py#L78-L163) · [src/nebula/v3/tools.py:281-394](https://github.com/berylliumsec/nebula/blob/7332d9a05127933d2cc649e6797c9586466cfa8a/src/nebula/v3/tools.py#L281-L394) · [src/nebula/v3/sandbox.py:270-299](https://github.com/berylliumsec/nebula/blob/7332d9a05127933d2cc649e6797c9586466cfa8a/src/nebula/v3/sandbox.py#L270-L299) · [src/nebula/v3/sandbox.py:1020-1032](https://github.com/berylliumsec/nebula/blob/7332d9a05127933d2cc649e6797c9586466cfa8a/src/nebula/v3/sandbox.py#L1020-L1032) · [src/nebula/v3/agent_tooling.py:74-86](https://github.com/berylliumsec/nebula/blob/7332d9a05127933d2cc649e6797c9586466cfa8a/src/nebula/v3/agent_tooling.py#L74-L86) · [src/nebula/v3/tools.py:1756-1777](https://github.com/berylliumsec/nebula/blob/7332d9a05127933d2cc649e6797c9586466cfa8a/src/nebula/v3/tools.py#L1756-L1777)

### How are scope, authorization and dangerous actions controlled? (answered)

Scope and safety are enforced at multiple layers, all rooted in the `ScopePolicy` domain object (`domain.py:728-760`).

**Target allowlists**: `ScopePolicy` defines `allowed_cidrs` (CIDR networks), `allowed_domains` (with `*.` wildcard for subdomains), `allowed_urls` (with path prefix matching), `allowed_ports` — or operator may set `allow_all_targets: true`. It also supports `prohibited_actions` (exact tool name or action string bans), `not_before`/`not_after` time windows, and `local_only` (blocks `cloud_transfer`).

**PolicyEngine** (`policy.py:194-300`) evaluates every tool invocation before execution. It checks time windows, prohibited actions, target normalization (`_normalize_target` parses URLs and host:port at `policy.py:87-144`), and scope matching (`_domain_allowed` at `policy.py:147-157`, `_ip_allowed` at `160-164`, `_url_allowed` at `167-191`). Critically, DNS resolution happens at policy time (not at tool time): `resolved_ips` are captured, so DNS rebinding can't widen scope (`policy.py:43`).

**Risk classification**: Each `ToolSpec` is tagged with a `RiskClass` (`domain.py:243-252`): `LOCAL_READ`, `PASSIVE`, `ACTIVE_SCAN`, `WORKSPACE_WRITE`, `CREDENTIAL_USE`, `EXPLOITATION`, `PERSISTENCE`, `DESTRUCTIVE`, `SCOPE_CHANGE`. Classes above `ACTIVE_SCAN` always require operator approval (`policy.py:197-203, 292-298`). Writes outside the workspace and credential use also always require approval (`policy.py:277-290`).

**Human-in-the-loop**: `ApprovalRequired` (`tools.py:204-209`) is raised by the broker and caught by the `_approval` graph node (`orchestration.py:1961-1980`). LangGraph's `interrupt()` pauses the mission, persisting the checkpoint. The operator approves, edits, or rejects through the UI; the run resumes from its checkpoint (`orchestration.py:639 resume()`). Approval cards are durable and survive core restarts. `ToolNotPermitted` (`tools.py:147-158`) refuses calls that a scope setting permanently blocks.

**Request-level authorization**: `McpApprovalMode` offers `RISK_BASED`, `ALLOW`, `ASK`, `DENY` per MCP server profile (`domain.py:498-503`). The first call to any MCP tool in a session triggers a what-changed capability snapshot shown to the operator.

**Sandbox isolation**: Container execution uses `docker/podman run` with `--network=none` by default. SCOPED mode adds iptables-level egress rules pinned to resolved IPs (`sandbox.py:270-299`). VPN mode routes through an OpenVPN profile. The container runs non-root (uid 65532:65532) with a read-only root filesystem by default (`sandbox.py:297-298`).

**Rate limits**: `ScopePolicy.max_concurrency` (default 1, max 256) limits parallel operations. `RunBudget.per_target_active_operations` (default 1) limits operations on the same target. `ToolSpec.timeout_seconds` (max 86400) bounds individual tool runs.

**Scope import** (`scope_import.py:1-100`) is a separate AI-assisted flow where the operator uploads a document (RFP, rules of engagement, etc.), the model extracts CIDR/domain/URL candidates, and the operator reviews and applies them — the model never writes scope directly.

> **Editor's note.** Correction: new Projects default to Host execution mode. Once the operator acknowledges it, run_command runs Bash on the host with host networking, scope is not applied to commands (only the time window), and the default on_boundary approval policy does not gate them. A bypass_permissions scope flag also makes the PolicyEngine allow everything.

Citations: [src/nebula/v3/domain.py:728-760](https://github.com/berylliumsec/nebula/blob/7332d9a05127933d2cc649e6797c9586466cfa8a/src/nebula/v3/domain.py#L728-L760) · [src/nebula/v3/policy.py:194-300](https://github.com/berylliumsec/nebula/blob/7332d9a05127933d2cc649e6797c9586466cfa8a/src/nebula/v3/policy.py#L194-L300) · [src/nebula/v3/policy.py:87-144](https://github.com/berylliumsec/nebula/blob/7332d9a05127933d2cc649e6797c9586466cfa8a/src/nebula/v3/policy.py#L87-L144) · [src/nebula/v3/sandbox.py:270-299](https://github.com/berylliumsec/nebula/blob/7332d9a05127933d2cc649e6797c9586466cfa8a/src/nebula/v3/sandbox.py#L270-L299) · [src/nebula/v3/tools.py:204-209](https://github.com/berylliumsec/nebula/blob/7332d9a05127933d2cc649e6797c9586466cfa8a/src/nebula/v3/tools.py#L204-L209) · [src/nebula/v3/scope_import.py:1-100](https://github.com/berylliumsec/nebula/blob/7332d9a05127933d2cc649e6797c9586466cfa8a/src/nebula/v3/scope_import.py#L1-L100)

### How are findings validated and reported? (answered)

Findings follow a **lifecycle from candidate through verified evidence to signed-off report**, tracked via `FindingStatus` (`domain.py:372-381`): `CANDIDATE` → `VALIDATED` → `CONFIRMED` / `FALSE_POSITIVE` / `ACCEPTED_RISK` / `REMEDIATED`.

**Candidate generation**: Specialists produce `SpecialistResult` objects containing `candidate_finding_ids`, `evidence_ids`, and `reproducible_steps` (`orchestration.py:174-186`). The `FINISH_TOOL` handler (`agent_tooling.py:856-886`) aggregates these across all of a specialist's turns, deduplicating evidence IDs and steps. A candidate finding enters the store with status `CANDIDATE`.

**Validation gate**: The `EvidenceVerifier` (`orchestration.py:341-363`) runs as the graph's `verify` node. It rejects any specialist result that has `candidate_finding_ids` but lacks `evidence_ids` ("candidate findings have no linked evidence") or lacks `reproducible_steps` ("candidate findings have no reproducible verification steps"). This is a **deterministic policy check**, not a second model review — evidence and reproduction steps are required before a finding can be promoted.

**Evidence** (`domain.py:2424-2439`): Each evidence entry records `evidence_type`, `sha256` (content hash), `artifact_id` (pointing to stored blob), `tool_call_id`, `execution_id`, `captured_by`. Artifacts (`domain.py:2442-2453`) store the raw bytes with `sha256`, `media_type`, `storage_path`, and a `redacted` flag.

**False positives and deduplication**: Findings can be manually moved to `FALSE_POSITIVE` status. The `correlation_ids` field on `Finding` (`domain.py:2480`) allows grouping related findings. The `finish_task` result aggregation at `agent_tooling.py:856-886` deduplicates across turns using `dict.fromkeys()` on evidence IDs, steps, and finding IDs.

**Reporting**: The `Report` entity (`domain.py:5273-5300`) collects `finding_ids`, `observation_ids`, and `artifact_ids`. Reports have a `DRAFT` → `REVIEW` → `FINAL` lifecycle. Final reports require operator `signed_off_by` and `signed_off_at` (`domain.py:5290-5299`). `ReportRenderService` (`reporting.py:87-130`) produces deterministic PDF from a frozen JSON snapshot — it hashes every referenced artifact, so a cached render is reused only if the report revision and all artifact content match. Failed renders are marked `INTERRUPTED` on core restart (`reporting.py:131-152`). The PDF uses bundled NotoSans fonts and the ReportLab library.

Per-engagement, the `SpecialistResult` also carries `remediation_id` for linking to the `Remediation` entity.


Citations: [src/nebula/v3/domain.py:372-381](https://github.com/berylliumsec/nebula/blob/7332d9a05127933d2cc649e6797c9586466cfa8a/src/nebula/v3/domain.py#L372-L381) · [src/nebula/v3/domain.py:2424-2453](https://github.com/berylliumsec/nebula/blob/7332d9a05127933d2cc649e6797c9586466cfa8a/src/nebula/v3/domain.py#L2424-L2453) · [src/nebula/v3/domain.py:5273-5300](https://github.com/berylliumsec/nebula/blob/7332d9a05127933d2cc649e6797c9586466cfa8a/src/nebula/v3/domain.py#L5273-L5300) · [src/nebula/v3/orchestration.py:341-363](https://github.com/berylliumsec/nebula/blob/7332d9a05127933d2cc649e6797c9586466cfa8a/src/nebula/v3/orchestration.py#L341-L363) · [src/nebula/v3/agent_tooling.py:856-886](https://github.com/berylliumsec/nebula/blob/7332d9a05127933d2cc649e6797c9586466cfa8a/src/nebula/v3/agent_tooling.py#L856-L886) · [src/nebula/v3/reporting.py:87-152](https://github.com/berylliumsec/nebula/blob/7332d9a05127933d2cc649e6797c9586466cfa8a/src/nebula/v3/reporting.py#L87-L152)

### How is engagement state and knowledge kept across a long run? (answered)

Engagement state is persisted across three independent stores.

**NebulaStore** (`storage.py`): The primary relational store (SQLAlchemy-backed, PostgreSQL or SQLite) holds all domain entities — `AgentRun`, `Task`, `ToolCall`, `Finding`, `Evidence`, `Artifact`, `Engagement`, `Approval`, `ChatSession`, `ContextSnapshot` and dozens more. The CLI uses Alembic for schema migrations (`cli.py:25`). `RunStatus` tracks lifecycle: `QUEUED → PLANNING → RUNNING → WAITING_APPROVAL/PAUSED/INTERRUPTED/CANCELLED/FAILED/COMPLETE` (`domain.py:391-401`).

**LangGraph Checkpoints**: The mission graph (`orchestration.py:511-556`) uses `AsyncSqliteSaver` (`orchestration.py:32`) with sync durability mode — every superstep is checkpointed before the next node starts. This enables `MissionRuntime.recover()` (`orchestration.py:642-659`) to resume any interrupted run from its last committed state. `RoutingJournal` (`orchestration.py:271-316`) records the model's routing response before any tool call executes, so a crash+recovery replays the same routing response instead of asking the model again — ensuring idempotent tool execution. Finished runs delete their checkpoints (`orchestration.py:675-698`).

**Context Compaction**: `ContextCompactor` (`context.py:1440-1470`) creates immutable `ContextSnapshot` entities for long-running conversations. The `WORKING_CONTEXT_CEILING` is 200K input tokens (`context.py:79`). Above this, the compactor uses a model to summarize prior conversation turns and stores the result as a `ContextSnapshot` with quality metadata and source references. The compactor targets 75% of the window and allows 60% of that for input (`context.py:69, 80`).

**Butler Memory** (`butler_memory.py:1-48, 166-200`): A separate SQLite database (not the main NebulaStore) with an optional Chroma vector index for semantic search. Memory scopes are `global_preference`, `global_lesson`, or `project_lesson`. Items are stored with `content`, `source_label`, `engagement_id`, timestamps, and revisions. The `_PREFERENCE` and `_LESSON_PROCESS` regex patterns (`butler_memory.py:51-84`) guide Butler's automatic judgment of what to save. The search index is rebuildable from the authoritative SQLite records. Butler's memory is explicitly separate from conversation context — it's durable, cross-project, and operator-visible through the Memory panel.

**Events and provenance**: Every significant state change is recorded as a `RunEvent` with idempotency keys (`orchestration.py:584-611`). The `ResourceRelation` entity (`domain.py:89-113`) creates provenance edges between resources (evidence "affects" finding, artifact "produced_by" execution) with revision tracking.

**Resumption**: The `resume()` entry point (`orchestration.py:639-659`) accepts an approval response for paused missions or `recover()` for crashed ones. The `NebulaStore` supports `ConflictError` with expected-revision checks to prevent lost updates during recovery.


Citations: [src/nebula/v3/orchestration.py:511-556](https://github.com/berylliumsec/nebula/blob/7332d9a05127933d2cc649e6797c9586466cfa8a/src/nebula/v3/orchestration.py#L511-L556) · [src/nebula/v3/orchestration.py:271-316](https://github.com/berylliumsec/nebula/blob/7332d9a05127933d2cc649e6797c9586466cfa8a/src/nebula/v3/orchestration.py#L271-L316) · [src/nebula/v3/orchestration.py:639-659](https://github.com/berylliumsec/nebula/blob/7332d9a05127933d2cc649e6797c9586466cfa8a/src/nebula/v3/orchestration.py#L639-L659) · [src/nebula/v3/context.py:54-80](https://github.com/berylliumsec/nebula/blob/7332d9a05127933d2cc649e6797c9586466cfa8a/src/nebula/v3/context.py#L54-L80) · [src/nebula/v3/context.py:1440-1470](https://github.com/berylliumsec/nebula/blob/7332d9a05127933d2cc649e6797c9586466cfa8a/src/nebula/v3/context.py#L1440-L1470) · [src/nebula/v3/butler_memory.py:1-48](https://github.com/berylliumsec/nebula/blob/7332d9a05127933d2cc649e6797c9586466cfa8a/src/nebula/v3/butler_memory.py#L1-L48)

### Which models are supported and how are cost and context managed? (answered)

Nebula supports **17 provider flavors** through a provider-abstracted gateway (`providers.py:198-223`): `OPENAI`, `ANTHROPIC`, `GEMINI`, `VERTEX`, `BEDROCK`, `AZURE_OPENAI`, `MISTRAL`, `COHERE`, `XAI`, `DEEPSEEK`, `GROQ`, `TOGETHER`, `FIREWORKS`, `OPENROUTER`, `OLLAMA`, `VLLM`, `LLAMA_CPP`, `SGLANG`, `LM_STUDIO`, `HUGGINGFACE_ENDPOINT`, `NVIDIA_NIM`, and `CUSTOM`.

**Model configuration** (`providers.py:256-363`): Each `ProviderConfig` specifies `base_url`, `default_model`, `model_allowlist` (restricts which models can be used), `api_key_env` (pulled from environment, never stored in the config row), `local` flag (required for private IPs, enforces `localhost`/private address check), `capabilities` (`ModelCapabilities` at `providers.py:237-253`: `streaming`, `tools`, `strict_tools`, `structured_output`, `vision`, `reasoning_controls`, `context_window`). Local endpoints using HTTP passthrough must be flagged `local: true` (`providers.py:333-346`).

**Model limits** (`known_model_limits.py`): A curated map of ~200 models with `(context_window, max_output_tokens)` tuples, auto-generated from OpenRouter's catalog. Ranges from 8K (older DeepSeek distill) to 2M (Gemini 1.5 Pro) context. These are used as fallbacks when the provider doesn't advertise limits.

**Model catalog** (`model_catalog.py:9-37`): `ModelDescriptor` carries `context_window`, `max_output_tokens`, `pricing` (decimal strings by billing unit), `input_modalities`, `output_modalities`, `reasoning_mandatory`, `route_limits` (per-provider route context windows verified via endpoint probing).

**Role-based model selection**: A `ProviderRegistry` (`providers.py:6500-6543`) supports `select(local_only=..., residency=..., required=...)` for capability-based routing. The `route()` method (`providers.py:6545`) orders providers by cost, locality, and capability requirements. Each mission can specify its own `provider_id` and `model` for the supervisor and individual specialists (`orchestration.py:565-576`).

**Cost management** (`domain.py:2560-2569`): `RunBudget` caps `max_tokens`, `max_cost_usd`, `max_tool_calls`. The API layer enforces `MAX_API_MISSION_TOKENS=200K` and `MAX_API_MISSION_COST_USD=100` (`missions.py:60-64`). Per-model pricing from `model_pricing.py` converts usage to cost via `combined_billed_cost()` and `usage_cost_usd()`.

**Context-window management** (`context.py:54-80`): Default output is `min(window/4, published_limit, 200K — input)`, with a floor of 8,192 tokens. The `WORKING_CONTEXT_CEILING=200K` prevents 1M+ models from bloating context before compaction runs. `CONTEXT_TARGET_FRACTION=0.75` sets when compaction triggers — at 75% of the effective window. Hard capacity checks still use the real model window.

**Harness support**: Beyond direct provider connections, Nebula supports Codex App Server (via the `claude-agent-sdk`) and Grok ACP as "harnesses" — alternative agent runtimes with their own model access, connected via stdio/Unix socket/WebSocket with bearer auth (`domain.py:414-442`). Harnesses are full agent sessions: the model in the harness makes its own tool calls, while Nebula's policy layer still intercepts and approves them.

> **Editor's note.** Correction: ProviderFlavor lists 25 kinds (including custom, microsoft_foundry, orcarouter, litellm), not 17. The harnesses are Codex App Server and Grok ACP; claude_agent_sdk is a retired kind kept only for old records. The API mission limits are ceilings on requested budgets, which default to unbounded.

Citations: [src/nebula/v3/providers.py:198-223](https://github.com/berylliumsec/nebula/blob/7332d9a05127933d2cc649e6797c9586466cfa8a/src/nebula/v3/providers.py#L198-L223) · [src/nebula/v3/providers.py:237-363](https://github.com/berylliumsec/nebula/blob/7332d9a05127933d2cc649e6797c9586466cfa8a/src/nebula/v3/providers.py#L237-L363) · [src/nebula/v3/providers.py:6500-6543](https://github.com/berylliumsec/nebula/blob/7332d9a05127933d2cc649e6797c9586466cfa8a/src/nebula/v3/providers.py#L6500-L6543) · [src/nebula/v3/known_model_limits.py:1-60](https://github.com/berylliumsec/nebula/blob/7332d9a05127933d2cc649e6797c9586466cfa8a/src/nebula/v3/known_model_limits.py#L1-L60) · [src/nebula/v3/context.py:54-80](https://github.com/berylliumsec/nebula/blob/7332d9a05127933d2cc649e6797c9586466cfa8a/src/nebula/v3/context.py#L54-L80) · [src/nebula/v3/missions.py:60-65](https://github.com/berylliumsec/nebula/blob/7332d9a05127933d2cc649e6797c9586466cfa8a/src/nebula/v3/missions.py#L60-L65)
