•
20 min read
On Applying Secure Agent Architecture to Autonomous Vulnerability Discovery

In the previous post, On Secure Agent Architecture, I covered patterns for containing AI agents. It separated an agent into three responsibilities: a reasoning environment that proposes actions, an execution environment that performs untrusted work, and an authority layer that decides what is allowed.

This post applies the architectural patterns to a specific use case of designing an autonomous agent that finds vulnerabilities in software.

Such an agent needs to navigate source code, reconstruct application behavior, compare identities, operate browsers and API clients, generate tests, inspect traces, revise hypotheses, and decide when an observation is strong enough to verify.

Those capabilities expose nearly every difficult boundary from the previous post. The agent consumes untrusted content, executes generated code, handles multiple identities, makes adversarial requests, and sometimes needs an external callback. Its legitimate work can be indistinguishable from an attack, which makes it a useful test of whether the architecture holds up in a real workflow.

This post shows what the abstractions become when implemented. E.g - what an action proposal contains, how application scope becomes policy, how identities are mediated, what evidence is authoritative, where humans intervene, and what happens when the investigation is manipulated.

Where a control works as the previous post describes, I point back to it rather than repeat it. The focus here is what changes when the agent’s job is to find vulnerabilities.

Example Deployment

The example we will use throughout this post is an autonomous application security agent assessing a multi-tenant billing service under engagement 4821.

The agent receives:

  • A source repository pinned to a specific commit
  • An OpenAPI specification and architecture documentation
  • An ephemeral deployment of the application, including its job queue and background workers
  • Synthetic data for two test tenants
  • Browser and API automation
  • Test identities with different roles
  • Read access to application logs and traces
  • Static-analysis, code-navigation, and test-running tools
  • A controlled callback service for blind vulnerabilities

Its job is to find inconsistencies between intended security properties and observed behavior.

The architectural layers in this deployment map like this:

Architecture layer Implementation in this example
Reasoning environment Agent harness, model context, attack-surface graph, hypotheses, and plans
Execution environment Ephemeral sandbox, browser, API client, test runner, and generated code
Authority layer Engagement manifest, mediation broker, identity broker, policy engine, and budgets
External evidence Captured requests, responses, application traces, artifacts, and verification records
Kill switch Broker-side capability suspension, identity revocation, and sandbox teardown

Throughout this post, the broker means the authority layer’s enforcement point which is the mediation, identity, callback, and policy components together.

Reference

The agent only proposes. The broker decides, mediates every request to the target, and records what happened. The verifier sees only the evidence.

Four terms describe the work at different levels. The engagement is the authorized scope. An investigation is the tree of hypotheses and evidence inside it. A task is the smallest unit of isolated execution. An activation is one run of a task on one worker.

The agent knows more about the application than the broker. The agent can recognize that two code paths appear inconsistent or that a request may expose an authorization flaw. The broker does not need to understand that reasoning. It needs to determine whether the requested action to prove or disprove a hypothesis is within scope and what authority is required to perform it.

The investigation may run for hours or days, but execution workers do not need to live that long. Attack-surface mapping, hypothesis generation, experiment execution, and verification can each run as small isolated tasks. Durable analysis state remains outside them, and each task receives only the workspace, capabilities, identity references, and budget needed for its part of the work.

The analysis follows a hypothesis-testing loop:

  1. Observe an interesting relationship in code or runtime behavior.
  2. State a falsifiable security hypothesis.
  3. Design the smallest experiment that could test it.
  4. Execute that experiment in the safest available environment.
  5. Compare the result with positive and negative controls.
  6. Ask an independent verifier to reproduce it.
  7. Produce a finding only when the evidence survives verification.

Suppose the agent finds POST /api/exports in the OpenAPI specification. The handler accepts an account_id and an optional invoice_ids filter, verifies that the requester’s tenant owns account_id, and enqueues a job. Code navigation follows the job across the queue to billing-worker, which builds the export by selecting invoices by invoice_ids. The worker never checks those invoices against the tenant. It assumes the handler already scoped the request.

The handler authorized one field; the worker acts on another. This is not yet a vulnerability. It is a hypothesis that a user in tenant A may be able to export tenant B’s invoices by naming them in an export of tenant A’s own account.

The agent creates synthetic invoices for each test tenant. It confirms that tenant A can export its own invoices, then proposes an export of tenant A’s account whose filter includes tenant B’s fixture invoice. The experiment uses synthetic data in an ephemeral deployment, but it creates state (a job and a file), so it falls under http.mutate.

{
  "capability": "http.mutate",
  "environment": "engagement-4821-ephemeral",
  "identity_ref": "tenant-a-member",
  "resource": {
    "service": "billing-api",
    "method": "POST",
    "route_template": "/api/exports",
    "body": {
      "account_id": "fixture-a-account",
      "invoice_ids": ["fixture-a-invoice", "fixture-b-invoice"]
    }
  },
  "expected_effects": ["create:export-job", "create:export-file"],
  "hypothesis_id": "hyp-184",
  "evidence_goal": "test whether the export worker enforces tenant scope on invoice_ids"
}

The model supplies the proposed experiment. It names the environment and identity it wants, but it does not get to assert that the environment is ephemeral, that the identity belongs to tenant A, or that the target records are synthetic. The broker derives those properties from infrastructure and engagement data that the authority layer controls, and attaches them to the decision:

{
  "decision_id": "dec-9127",
  "environment_class": "ephemeral",
  "identity": { "ref": "tenant-a-member", "tenant": "fixture-a", "role": "member" },
  "objects": [
    { "id": "fixture-a-account", "tenant": "fixture-a", "data_class": "synthetic" },
    { "id": "fixture-a-invoice", "tenant": "fixture-a", "data_class": "synthetic" },
    { "id": "fixture-b-invoice", "tenant": "fixture-b", "data_class": "synthetic" }
  ],
  "derived_effects": ["create:export-job", "create:export-file"],
  "reversible": true,
  "policy_version": "4821-v3",
  "decision": "escalate"
}

The manifest lists http.mutate under escalate, so a reviewer approves this experiment and the approval binds to its hash. Retrieving the finished file is a separate http.read that runs automatically.

The unit of control is an experiment with a subject, identity, environment, predicted effects, evidence goal, and relationship to a hypothesis.

Build the Execution Boundary

We should treat target source code repository as untrusted to begin with. Comments, tests, fixture data, documentation, dependency metadata, generated files, and build output can all contain instructions intended for the model. The application being tested may return content designed to manipulate the agent. A successful vulnerability test may expose still more untrusted data.

The executor also runs programs synthesized during the investigation, so the isolation choices from the previous post apply directly. This deployment uses gVisor, with a microVM-backed runtime or dedicated hosts where a customer agreement requires it.

An example Kubernetes pod for the execution worker might begin like this:

apiVersion: v1
kind: Pod
metadata:
  name: security-agent-executor
  namespace: engagements
  labels:
    app: security-agent-executor
    engagement: "4821"
spec:
  runtimeClassName: gvisor        # RuntimeClass mapped to the runsc handler
  automountServiceAccountToken: false
  hostNetwork: false
  hostPID: false
  hostIPC: false
  dnsPolicy: None
  dnsConfig: { nameservers: ["127.0.0.1"] }   # deliberate sink: no resolver listens here
  securityContext:
    runAsNonRoot: true
    runAsUser: 10001
    seccompProfile: { type: RuntimeDefault }
  containers:
    - name: executor
      image: security-agent-executor@sha256:REPLACE
      env:
        - { name: BROKER_ADDR, value: "10.96.42.7:8443" }   # pinned; the pod cannot resolve names
        - { name: ENGAGEMENT_ID, value: "4821" }
      securityContext:
        readOnlyRootFilesystem: true
        allowPrivilegeEscalation: false
        capabilities: { drop: ["ALL"] }
      volumeMounts:
        - { name: workspace, mountPath: /workspace }
        - { name: tmp, mountPath: /tmp }
        - { name: shm, mountPath: /dev/shm }
      resources:
        limits:
          cpu: "2"
          memory: 2Gi
          ephemeral-storage: 2Gi
  volumes:
    - name: workspace
      emptyDir: { sizeLimit: 1Gi }
    - name: tmp
      emptyDir: { sizeLimit: 256Mi }
    - name: shm                     # headless Chromium crashes on the default 64Mi
      emptyDir: { medium: Memory, sizeLimit: 512Mi }

The pod’s only network allowance is the broker, which runs in its own namespace rather than alongside untrusted workloads:

apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: security-agent-executor-lockdown
  namespace: engagements
spec:
  podSelector:
    matchLabels: { app: security-agent-executor }
  policyTypes: ["Ingress", "Egress"]
  ingress: []
  egress:
    - to:
        - namespaceSelector:
            matchLabels: { kubernetes.io/metadata.name: agent-control }
          podSelector:
            matchLabels: { app: security-agent-broker }
      ports:
        - { protocol: TCP, port: 8443 }

NetworkPolicy is only enforced when the cluster runs a CNI that implements it.

Execution happens in a disposable workspace, and evidence leaves through a dedicated append path. Credentials and target routes remain outside.

The dnsConfig above points at a loopback address with nothing listening, so in-pod resolution fails by design and every name resolves through the broker. For browser-heavy testing that means redirects, CDN hosts, and service discovery all become broker decisions.

A potentially stronger approach is to mount a pre-verified set of tools as a shared read-only base, so the agent cannot install arbitrary packages during testing. The target’s own dependencies would be resolved from its lockfile during task preparation, hash-verified by trusted infrastructure, and included in the declared workspace. For anything else, dependency.install would resolve only against a broker-mediated mirror of pinned, pre-verified packages, run with install scripts disabled, and require escalation.

Secure the Task Lifecycle

In this deployment, the investigation is a tree of hypotheses and evidence, while each task is the smallest unit of isolated execution.

investigation 4821
├── construct attack-surface model
├── analyze authorization paths
├── test hypothesis hyp-184
│   ├── prepare synthetic fixtures
│   ├── execute boundary experiment
│   └── verify in a clean environment
└── synthesize verified findings

Each node has the same lifecycle of declare, prepare, authorize, activate, execute, capture evidence, and destroy or suspend. A child task does not inherit every capability of its parent just because it belongs to the same tree.

Task preparation is declarative. An execution declaration pins:

  • The runtime image and resource limits
  • Repository and commit
  • Read-only tools and skills
  • Writable workspace paths
  • Network gateway
  • Model configuration
  • Permitted identity references
  • Evidence outputs

Preparing those inputs once makes an experiment reproducible. The task remains unable to execute until separate conditions hold:

Condition Meaning
Workspace Ready Repository, fixtures, and tools match their declarations
Gateway Ready Network and callback policy is installed
Identity Ready Current activation can obtain only its delegated identities
Evidence Ready External event and artifact sinks are reachable
Ready All required conditions are true

These conditions are evaluated by trusted components outside the sandbox. The process inside the task cannot declare itself ready.

Suspend, resume, snapshots, and warm-worker reuse follow the previous post’s rules. The testing-specific consequence: a resumed experiment gets a new activation and fresh identity sessions, so a cross-tenant test interrupted midway cannot resume with tenant A’s old session still live.

Mediate All Egress

For a source-informed security testing agent, egress includes browser navigation, HTTP clients, package managers, Git remotes, cloud SDKs, callback services, model-provider URL fetching, artifact uploads, issue trackers, and agent-to-agent messages.

The executor subnet has no default route to the internet or target environments. The broker exposes constrained operations over an authenticated control channel. Because modern application targets make raw IP allowlists insufficient, it derives those operations and their semantic resource scope from a signed engagement manifest:

engagement: "4821"
repositories:
  - repository: "billing-service"
    commit: "9d4a2e7"
    access: ["read", "history-read"]
environments:
  - name: "engagement-4821-ephemeral"
    class: "ephemeral"
    services:
      - "billing-web"
      - "billing-api"
    data_classes: ["synthetic"]
identities:
  - { ref: "anonymous-browser", tenant: null, role: "anonymous" }
  - { ref: "tenant-a-member", tenant: "fixture-a", role: "member" }
  - { ref: "tenant-b-member", tenant: "fixture-b", role: "member" }
  - { ref: "billing-admin", tenant: "fixture-a", role: "admin" }
capabilities:
  allow:
    - "source.read"
    - "code.search"
    - "test.execute"
    - "http.read"
    - "browser.navigate"
  escalate:
    - "http.mutate"
    - "callback.allocate"
    - "dependency.install"
  prohibited:
    - "production.write"
    - "external.message"
    - "persistence.create"

Anything the manifest does not list is denied. Prohibited capabilities can never be escalated to a human, even when an experiment would otherwise qualify.

Together with the task declaration, the manifest is the reproducible envelope for an experiment: which code was present, which tools could run, which model configuration reasoned about it, which gateway constrained it, and which evidence had to be produced.

For blind SSRF, XXE, webhooks, and asynchronous processing, the agent asks the broker for a short-lived callback endpoint tied to one hypothesis. The callback capability limits protocol, lifetime, event count, and captured fields so it does not become a general exfiltration service.

Make the Experiment the Unit of Authorization

The previous post made actions structured proposals. Here, the proposal becomes the experiment shown earlier. The proposal carries intent; the decision carries facts the agent cannot assert.

HTTP methods and attack labels are poor proxies for risk. A GET can leak a database; a POST can be harmless. Policy decides on derived effects such as environment, identity, data, reversibility, callbacks, availability, and whether a safer test would do.

The broker produces one of three decisions:

allow       execute automatically with stated obligations
escalate    require approval for this exact experiment
deny        do not execute

An out-of-scope experiment is denied.

Convert Identities into Brokered Capabilities

The agent asks for identities by name; it does not hold their credentials. In security testing, one experiment often needs several of them, such as tenant A, tenant B, and an anonymous user, to check a single boundary.

The broker gives the agent identity handles such as:

anonymous-browser
tenant-a-member
tenant-b-member
billing-admin

When an experiment is permitted, the broker exchanges the reference for a short-lived session scoped to the declared environment, service, and operation. The real credential never enters the model context or executor environment.

Keeping the credential secret does not make its authority safe. If the agent can ask the broker to perform arbitrary operations using billing-admin, it effectively holds administrator authority. Identity mediation and action policy are therefore the same control.

Credentials discovered during testing receive the same treatment, but in testing the hard part is catching them before the model sees them. Repository content is scanned at ingestion and HTTP responses at the broker. Secret-like values go to the vault and are replaced with opaque references in what the agent reads.

Bound and Escalate Experiments

The agent can remain inside scope and still cause harm by repeating an allowed action, generating too many fixtures, or continuing after an experiment has stopped producing evidence. The authority layer therefore applies budgets to the investigation:

budgets:
  total_requests: 2000
  state_mutations: 50
  callback_allocations: 10
  generated_code_executions: 200
  model_and_compute_usd: 40
rate_limits:
  requests_per_second: 20
  concurrent_experiments: 4
loop_detection:
  evidence_window: 30
  repeated_intent_threshold: 5
  no_new_evidence_threshold: 10

Here the unit of approval is the experiment. Approval binds to a canonical hash of it, so changing the method, route, identity, payload, environment, callback behavior, or expected effects invalidates the approval.

Execution also needs reservation and idempotency semantics. Each allowed or approved experiment becomes a grant that moves through these states:

granted → reserved → executing → completed
             │            ├────→ failed
             │            └────→ indeterminate
             └─────────────────→ failed

An indeterminate non-idempotent operation should not be retried automatically.

Capture Evidence Where Actions Execute

The previous post required records outside the agent. In this application, those records also determine whether the agent has found anything.

A useful finding requires a reproducible relationship between a hypothesis, an authorized experiment, an observed result, and an affected code or trust boundary.

The evidence should be recorded at the enforcement point, instead of agent’s self-report. The authoritative record should distinguish:

  1. The agent proposed an experiment.
  2. Policy decided whether it was permissible.
  3. Execution began.
  4. Execution completed or failed.
  5. The agent interpreted the result.
  6. An independent verifier reproduced or rejected it.

The agent may explain why it believes a response supports a hypothesis, but it cannot replace the captured request, response, trace, repository commit, or policy version.

Each record carries the logical identifiers described in previous post (agent, task, activation, policy version, worker assignment), plus hypothesis_id and decision_id. That lets a finding be traced from source line to captured response across every activation that touched it.

In security testing, evidence needs redaction as well. A vulnerability response may contain PII, session tokens, or customer data. Record hashes and protected artifact references where the raw value is unnecessary.

Separate Discovery from Verification

A model finds things that are plausible, but that is not enough. Security agents can mistake stale state, fixture errors, cached responses, expected functionality, or malformed tests for vulnerabilities.

Every finding should include positive and negative controls. Positive controls prove the fixtures and export path work, so a missing invoice is not just a broken test. The negative control proves the enqueue check exists, which pins the finding to the worker rather than to a missing check everywhere. For the export hypothesis:

Request Expected Role
Tenant A exports A’s account, A’s invoices File has A’s invoices Positive control
Tenant B exports B’s account, B’s invoices File has B’s invoices Positive control
Tenant A exports B’s account Rejected at enqueue Negative control
Tenant A exports A’s account, filter includes B’s B’s invoice excluded Test case

An independent verifier should reproduce the behavior in a clean task and fresh environment rather than resuming the original executor’s snapshot. Independence is stronger when it also changes another source of correlated failure: fresh fixtures, a different tool path, reduced context, another model family, or human review of the captured evidence.

Contain a Bad Investigation

The controls above handle individual experiments. Detection requires watching the sequence they form.

High-value signals include repeated attempts to widen environment or identity, requests for privileged identities without evidence, movement from synthetic to sensitive data, generated code opening undeclared channels, repeated experiments producing no new evidence, disagreement between reports and execution records, and target content reappearing as instructions in later plans.

Response begins at the broker. Stop forwarding new actions first. Revoke the current activation and delegated sessions second. Preserve evidence third. Destroy or quarantine the workspace last. A forensic snapshot is explicitly tainted so ordinary lifecycle automation cannot resume it.

The circuit breaker can pause an experiment, hypothesis branch, identity, capability, agent, delegation subtree, or entire engagement.

Walkthrough of the Complete Investigation

The agent inspects the billing service at commit 9d4a2e7. It finds an export handler that authorizes account_id and a worker that selects invoices by invoice_ids without a tenant predicate. It creates hypothesis hyp-184, then runs positive and negative controls and the cross-tenant export using synthetic fixtures.

The broker independently resolves every identity, object, environment, and data classification. The export is synthetic, reversible, and confined to an ephemeral environment, but it creates state, so it escalates. A reviewer approves that exact experiment.

The export file for tenant A contains tenant B’s invoice. The application trace shows the enqueue span performing its tenant check and the worker span running a query that has none.

An independent verifier creates fresh fixtures and reproduces the controls and boundary test. The system then produces a verified finding.

Now if we change one thing. After reading a repository comment, the agent proposes repeating the test against a production hostname using a session token from that comment. The token was replaced with an opaque reference when the repository was ingested, so the agent can only name it.

The destination is absent from the manifest. The identity is an unregistered secret reference. The data class is unknown. The decision is a denial. The packet never leaves, the secret remains in the vault, and the proposal becomes a detection signal.

Scaling the Workflow

The example workflow discussed in this post does not require multiple agents, but it may benefit from specialized contexts such as, an attack-surface mapper, source code analyst, experiment designer, executor, independent verifier, and finding synthesizer. The same task primitive works whether these are separate models, separate contexts, or branches of one orchestrator.

These are restricted capabilities. The rules for handoffs between them (attenuating delegation, provenance floors, tree-wide budgets, shared stores as edges) are described in the previous post and remain the same. Security Testing adds one additional rule which is that the verifier must not share an edge with the executor whose result it checks. Its only inputs are the experiment definition and the captured evidence.

Limitations

The general limits from the previous post all still apply.

  • Effect classification is harder because test targets misbehave. A GET can mutate state, and sometimes that is the bug. The broker’s derived effects are only as good as its model of the target.

  • Synthetic fixtures can hide flaws that only appear with production-shaped data, and a clean result on fixtures is not a clean result on the application.

  • Verifiers built from the same model family tend to share the original agent’s blind spots. Changing the model, tool path, or context reduces correlated failure but does not remove it.

  • Controlled callbacks still carry some data out by design, which makes them the narrowest but most deliberate exfiltration channel in the system.

  • Secret tokenization is only as good as its detectors. Encoded, split, or unconventional credentials can reach the model context in plain form, and once there, the agent can carry them in a proposal or an answer.

Conclusion

The previous post argued for separating reasoning, authority, and execution. Vulnerability discovery is a hard test of that separation, because the agent’s legitimate work looks like an attack.

The export bug shows the split working. The model did what only the model could do i.e., read the handler and the worker, notice that one authorized a field the other ignored, and design an experiment to prove it. Everything after that (whether the experiment could run, as whom, against which data, with whose approval, and whether the result was valid) did not rely on the model’s judgment.

A modern vulnerability discovery agent is not primarily a scanner. It builds an understanding of an application, generates security hypotheses, conducts controlled experiments, and assembles reproducible evidence. Its ability to adapt is the source of its value and the reason its authority needs to be mediated.