PentestAgent Lets AI Autonomously Hack Systems With Self-Spawning Agents
PentestAgent is an open-source AI framework that autonomously runs black-box penetration tests, orchestrating multi-agent crews with real security tools via MCP
Takeaways
- What it is: PentestAgent is an open-source Python framework (MIT, 2.6k stars) for autonomous black-box security testing using LLMs like Claude or GPT-5.
- Self-spawning agents: In Crew mode, a parent agent spawns isolated child agents on demand to parallelize recon and exploitation tasks with no external orchestration.
- MCP-native: Consumes external MCP tool servers and exposes itself as one, enabling integration with Claude Desktop, Cursor, and custom pipelines.
- Docker + Kali image: Ships a pre-built Kali Linux Docker image with Metasploit, Hydra, sqlmap, and more -- agent calls tools directly via terminal.
- Prebuilt playbooks: Structured attack workflows (e.g.
thp3_web,thp3_network) runnable from CLI against a target in one command. - Free to use: MIT license, requires only a LiteLLM-compatible API key; available on GitHub.
PentestAgent is an open-source Python framework that lets an LLM-backed agent autonomously conduct black-box security assessments -- running real tools like nmap, sqlmap, and msfconsole against a target, reasoning about what it finds, and deciding what to probe next. With over 2,600 stars and 515 forks on GitHub, it has become one of the more practically-oriented entries in the fast-growing agentic pentesting space.
The framework represents a shift from traditional script-based pentesting tools to intelligent, autonomous agents that can reason about security vulnerabilities, plan attack strategies, and execute complex testing workflows with minimal human intervention. It is free, MIT-licensed, and works with any LLM provider supported by LiteLLM -- OpenAI, Anthropic, or a self-hosted relay.
Four modes, one TUI
PentestAgent operates through a terminal user interface (TUI), offering modes for assisted chats, autonomous agents, and multi-agent crews, making it accessible for pentesters seeking AI augmentation without sacrificing control. The four modes map to different levels of autonomy:
- Assist (
/assist) -- single-shot instruction with tool execution, you stay in the loop - Agent (
/agent) -- fully autonomous execution of one task end-to-end - Crew (
/crew) -- an orchestrator LLM spawns specialized worker agents and coordinates them - Interact (
/interact) -- guided chat where the agent advises you step by step
You can switch between modes mid-session, cancel any running agent with Esc, and restore past sessions from the built-in conversation history browser. PentestAgent automatically persists every conversation so you can review, compare, and restore past sessions, with auto-save triggering after each task and before clearing.
The self-spawning agent architecture
The most architecturally interesting piece is how Crew mode works. A built-in spawn_mcp_agent tool allows a running agent to spawn a child copy of itself as a subordinate MCP server. The child process is fully isolated -- its own runtime, LLM client, conversation history, and notes store -- and its complete tool set is injected back into the parent agent's available tools after spawning. This enables hierarchical, multi-agent workflows without any external orchestration: the agent self-organises by delegating scoped subtasks to children it spawns on demand.