runPentestAgent
Runs Apex’s full pentest workflow, the same one pensar pentest and the TUI’s /pentest use:
- Discovery. Maps the attack surface. With
cwdit reads the source code (whitebox); otherwise it probes the livetarget(blackbox). - Pentesting. Spawns a targeted pentest agent for each discovered endpoint, up to 10 at a time.
- Reporting. Groups findings by root cause and writes
pentest-report.mdandpentest-report.jsonto the session directory.
Token usage is saved to the session whether the run succeeds or fails. When the run finishes, a short summary of the findings and artifact paths is printed to stdout.
Parameters
Live target URL, domain, or IP. Required in whitebox mode too: the pentest phase always runs against the live service.
Session that receives findings, POCs, logs, and the report. Create one with sessions.create(). Its config controls scope, credentials, headers, and safety settings for the run.
Model ID, for example "claude-opus-4-6". See Models.
AI provider credentials. Usually buildAuthConfig(await config.get()). See Configuration.
Path to the target’s source code. Enables whitebox attack surface discovery.
Receives streaming text, tool calls, sub-agent lifecycle, and workflow phase events. See AgentEventBus.
Cancels the run. See Errors and cancellation.
Extra guidance injected into the discovery agents’ system prompts (for example, “Focus on authentication bypass”).
Raw threat model content. Apex wraps it with standard instructions and injects it next to prompt.
Extended-thinking setting for supported models. See Reasoning.
Enable extended thinking for supported models. Prefer reasoning for new code.
Skip attack surface discovery and the swarm. Runs a single operator in one tight recon-to-exploit loop against target.
native runs Apex’s finding judge and returns structured findings. external skips the judge and returns concise reportedFindings for your own evaluator.
Whitebox only. Set to false to skip deterministic @pensar/surface enumeration and use the discovery agents for every app.
Called after every agent step, with the AI SDK step result (including token usage).
Returns
Promise<PentestWorkflowResult>
Every documented vulnerability. Empty when findingPolicy is external.
Short vulnerability title.
Severity rating.
Affected URL or endpoint.
What the vulnerability is.
What an attacker can achieve.
Proof gathered during exploitation.
Path to the proof-of-concept script in the session’s pocs/ directory.
How to fix it.
CWE mappings, when known.
Shared identifier for findings with the same root cause.
Concise findings for external evaluation. Only set when findingPolicy is external.
Per-objective status from every swarm worker. Only set when findingPolicy is external.
Absolute path to the session’s findings/ directory.
Absolute path to the session’s pocs/ directory.
Absolute path to pentest-report.md. null when no report is written, for example when findingPolicy is external.