Autonomous Red Teaming at Scale: Why PentestCode Replaced Monolithic LLM Prompts with Graph-Driven Swarms

Autonomous Red Teaming at Scale: Why PentestCode Replaced Monolithic LLM Prompts with Graph-Driven Swarms

By Reggi, 18 Jul 2026

Single-prompt LLM agents fail the moment a penetration test transitions from simple network scanning to dynamic exploit chaining. When an LLM tries to maintain terminal state, parse raw output, and plan attack paths in a single context window, it inevitably hallucinates or drops critical indicators. PentestCode, an open-source hard fork of OpenCode built by Zhangir Ospanov, solves this architectural bottleneck by applying the HPTSA strategist-coordinator pattern. The result is a specialized 13-agent engine that delivers a reported 4.3x performance boost over single-agent setups.

The Strategist-Coordinator Engine

Instead of relying on a generalized chatbot model with generic shell execution privileges, PentestCode executes offensive workflows through structured state transitions. You supply a root target and a primary objective, such as compromising a target IP to secure Domain Admin privileges. The primary coordinator agent receives this instruction and drives execution across specialized sub-agents.

+-------------------------------------------------------------+
|                      PentestCode Core                       |
|                   (Coordinator / Strategist)                |
+------------------------------+------------------------------+
                               |
        +----------------------+----------------------+
        |                      |                      |
        v                      v                      v
+---------------+      +---------------+      +---------------+
| Recon/Scan    |      | Exploitation  |      | Post-Exploit  |
| Sub-Agents    |      | Sub-Agents    |      | Sub-Agents    |
+-------+-------+      +-------+-------+      +-------+-------+
        |                      |                      |
        +----------------------+----------------------+
                               |
                               v
             +-----------------------------------+
             |    Shared Real-Time State Graph   |
             |  (Hosts, Creds, Vulns, Traversal) |
             +-----------------------------------+

The system initiates an Nmap sweep, parses the returned open ports, and checks for foundational patterns. Discovering open ports 88 and 389 immediately flags the target as an Active Directory Domain Controller.

From that point, execution fans out into parallel threads:

  1. Targeted Enumeration: The coordinator spawns isolated sub-agents to interrogate SMB, LDAP, and HTTP services simultaneously.
  2. Credential Extraction: Sub-agents initiate AS-REP roasting to harvest Kerberos ticket hashes for offline cracking.
  3. Lateral Movement: Captured credentials are systematically sprayed across discovered network entry points, including SMB, WinRM, LDAP, and RDP.
  4. Privilege Escalation & Post-Exploitation: Upon a successful WinRM authentication, a dedicated post-exploitation agent triggers automatically, dumping SAM, LSA, and DPAPI secrets.

Every command run, vulnerability detected, and credential harvested is logged to a verified evidence chain, giving operators a comprehensive log of the entire test.

Real-Time State Management and Attack Pathing

Passing gigabytes of raw terminal output between multiple agents burns context windows and pollutes LLM reasoning. PentestCode bypasses this issue by introducing a centralized, persistent engagement state that synchronizes findings across all 13 agents in real time.

State ComponentInternal Data TrackedRole in Automation
Asset RegistryDiscovered hosts, services, and live network interfacesKeeps agents aligned on target boundaries
Vulnerability DBDiscovered flaws, associated confidence scores, and status flagsPrevents duplicate exploits and prioritizes high-yield bugs
Credential StoreCleartext passwords, hashes, tokens, and access tiersFeeds the spray engine for rapid privilege escalation
Relationship GraphLabeled entity nodes connected by access pathwaysProvides input data for graph traversal algorithms

The built-in attack path module parses this relationship graph using cost-based Dijkstra and Yen’s K-shortest-paths algorithms. Instead of guessing the next offensive move, PentestCode calculates the most efficient mathematical route through compromised nodes directly to the objective.

Because this state engine persists across sessions, operators can pause, refine, and resume multi-day assessments without losing discovery data.

Tooling, Parsers, and Markdown Skill Packs

Allowing an LLM to hallucinate regex patterns over messy tool outputs is a recipe for missed footholds. PentestCode enforces strict data ingestion through 18 custom-tuned security tools paired with mandatory output parsers.

bash
# Conceptual flow: Raw security tool output is forced through dedicated parsers [Raw Tool Output: Nmap / Nuclei / NetExec / BloodHound / sqlmap] [Mandatory Structured State Parsers] [Unified Real-Time Engagement Graph]

Raw stdout streams from core tools like Nmap, Nuclei, NetExec, Gobuster, BloodHound, and sqlmap must pass through dedicated parsers that translate findings into structured graph entries before the coordinator can read them. Custom utility modules also handle:

  • Scope boundary validation
  • JWT analysis and verification
  • Cross-Site Scripting (XSS) detection
  • Credential-spray planning and rate management
  • Network tunnel orchestration
  • Automated client-ready report generation

Domain logic is decoupled from the core framework through 19 on-demand skill packs. These Markdown-based operational playbooks contain phase checklists, service enumeration guides, and exploitation playbooks across Active Directory, cloud systems, and web application targets. You can expand the agent's domain capabilities simply by writing structured Markdown, completely bypassing the need to modify the core codebase.

Operational Trade-offs

PentestCode provides strong mechanical automation, but it is not a complete replacement for manual operator skill. Engineering teams need to account for clear operational constraints:

  • OPSEC and Noise: PentestCode is not stealthy. Its aggressive multi-agent scanning and enumeration approach trips modern detection rules quickly, making it poorly suited for evasion-focused red team engagements.
  • Tool Redundancy: The coordinator can occasionally schedule redundant tool execution runs over the same endpoints during state synchronization delays.
  • Token Overhead: Multi-agent operations carry real cost. Live assessments typically burn between $5 and $50 in API tokens per engagement, depending on target size and model selection. Testing shows Claude Opus and Sonnet outshine models like GPT-4o and local LLMs when managing multi-agent state coordination.
  • Beta Lifecycle: The platform remains in active beta. The framework lacks a dedicated GUI, provides no Burp Suite integration, and features an API that is still evolving.

PentestCode operates best as an automated force multiplier. It takes over the heavy lifting of continuous enumeration, credential spraying, and structured data collection, freeing experienced security engineers to focus their time on complex attack chains and custom exploit development.


Popular Reads