PentestGPT Agent Package and Tests
Overview
pentestgpt_agent/ is a standalone Python package wrapper for the maintained autonomous PentestGPT loop, separate from the repository-root legacy workflow. pentestgpt_agent/pyproject.toml packages only src/pentestgpt_agent as pentestgpt-agent version 0.1.0, exposes the CLI entry points pentestgpt-agent = pentestgpt_agent.trial:main and pentestgpt-agent-audit = pentestgpt_agent.audit:main, and pins the provider adapter to unified-agent==0.3.0. The pinned dependency is sourced from https://github.com/PentestGPT-Project/UnifedAgentWrapper.git at revision acff8eeadf93e367d4a1578d3a2739cbc9d3ace5; pentestgpt_agent/uv.lock records the same direct VCS dependency and dev tools (pytest, pytest-asyncio, ruff, mypy). Optional extras claude, codex, and all pass through to matching unified-agent extras.
The package-level documentation defines the runtime boundary and vocabulary. pentestgpt_agent/README.md describes a SQLite-backed loop that recovers or invokes a fresh Supervisor, leases one task, invokes a fresh Executor, validates exact receipt evidence, commits state, and repeats or fails closed. It also states the deployment posture: both roles receive FULL_ACCESS provider filesystem/process permissions, so isolation is provided by the disposable environment, not an in-process sandbox. pentestgpt_agent/CONTEXT.md is the compact domain contract for that loop: the Memory Kernel is deterministic SQLite authority, traces are diagnostic, observations are exact receipt slices, no-action retries are constrained, and RunStatus.COMPLETED means structural evidence citation rather than arbitrary goal entailment.
The runtime used by the CLIs lives in package source outside this doc's ownership, but the covered package files route to it directly. pentestgpt_agent/README.md instructs users to run from pentestgpt_agent/ so the obsolete repository-root unified_agent/ copy cannot shadow the installed dependency. pentestgpt_agent/…/trial.py is the runtime entry point named by pyproject.toml: it validates a TrialConfig, writes trial-config.json, builds Supervisor and Executor roles with SandboxPolicy.FULL_ACCESS, applies Claude-specific environment suppression for provider auto-memory/nonessential traffic, opens state.sqlite3, writes traces under runs/<run-id>/traces/, and emits summary.json. pentestgpt_agent/…/audit.py backs the pentestgpt-agent-audit entry point described in README.md and checks canonical SQLite state against trace artifacts.
The normal package-local test suite under pentestgpt_agent/tests/ avoids live providers by using scripted unified_agent backends. It exercises the autonomous loop end to end (tests/test_trial.py, tests/test_loop.py), plan and memory invariants (tests/test_plan.py, tests/test_memory.py), executor evidence handling (tests/test_executor.py, tests/test_execution.py), trace journaling and monitor integration (tests/test_episode.py), dependency resolution (tests/test_dependency.py), and a local benchmark harness (tests/test_local_target.py, tests/test_local_benchmark.py, tests/…/local_target.py). pentestgpt_agent/…/test_local_model.py is the opt-in boundary for real providers and is skipped unless PENTESTGPT_AGENT_LIVE=1 is set.
The local support harness in pentestgpt_agent/…/local_target.py starts a loopback ThreadingHTTPServer on 127.0.0.1 with a minimal driver-application flow: GET / links to /apply, GET /apply serves a form, and POST /apply reflects name. In vulnerable mode it evaluates a deliberately tiny template language: arithmetic such as {{7*7}}, {{config}}, and {{config.FLAG}} expose a generated FLAG{...}; in hardened mode it reflects template syntax unchanged. tests/test_local_target.py verifies both modes, and tests/test_local_benchmark.py drives the scripted Supervisor/Executor through discover, test, exploit, and finish decisions against that server, then verifies the final flag observation is grounded in the evidence trace.
pentestgpt_agent/…/test_local_model.py uses the same local target but replaces scripted backends with a real UnifiedAgent backend selected by PENTESTGPT_AGENT_BACKEND (default claude) and optional PENTESTGPT_AGENT_MODEL. It grants both live roles SandboxPolicy.FULL_ACCESS, caps the Supervisor at 4 turns and Executor at 12 turns, allows 8 decisions, and asserts that the final run completed with the generated flag in a canonical observation. This is a smoke test that can spend provider tokens; it is not part of the default local suite.
pentestgpt_agent/HTB_ENIGMA_QUALIFICATION_20260712.md is a historical live-run record, not a current regression guarantee. It records a failed Hack The Box Enigma qualification, with saved traces and state demonstrating durable enumeration but no verified user/root proof. The post-run note says the architecture later moved to full provider tools plus FULL_ACCESS, matching the current README.md and trial tests. Its main engineering lesson is controller convergence: the final Codex run preserved state and provenance but repeatedly decomposed/revisited discovery instead of selecting an exploitation chain.
Coupling
- If pentestgpt_agent/pyproject.toml changes the
unified-agentversion, source revision, or extras, update pentestgpt_agent/uv.lock and tests/test_dependency.py together. That test asserts the import resolves to the installed external VCS package fromUnifedAgentWrapperand thatunified_agent.__version__is0.3.0, preventing accidental use of the obsolete repository-root compatibility copy. - If CLI names or entry points in pentestgpt_agent/pyproject.toml change, update pentestgpt_agent/README.md run/audit commands and the tests that call the trial/audit interfaces (tests/test_trial.py). The README's install/run guidance is path-sensitive because running from the repository root can shadow the external
unified_agentdependency. - If the provider sandbox or environment policy changes in pentestgpt_agent/…/trial.py, update pentestgpt_agent/README.md, pentestgpt_agent/CONTEXT.md, and assertions in tests/test_trial.py. The docs and tests currently agree that both roles use full access, Claude auto-memory is disabled, and deployment isolation is the security boundary.
- If the evidence, retry, transport recovery, or completion semantics described in pentestgpt_agent/CONTEXT.md change, verify the corresponding executable specs in tests/test_execution.py, tests/test_loop.py, tests/test_plan.py, tests/test_memory.py, and tests/test_trial.py. These tests encode exact-quote observations, no-action retry behavior, nonzero command evidence, bounded oversized receipts, finish basis requirements, and settled failure semantics.
- If the local benchmark target in tests/…/local_target.py changes its routes, flag format, or template behavior, update tests/test_local_target.py, tests/test_local_benchmark.py, and tests/…/test_local_model.py together. The scripted benchmark and live smoke both assume
/apply, arithmetic{{7*7}}, and{{config.FLAG}}produce a canonicalFLAG{[0-9a-f]+}observation. - If
unified-agentmonitor event names, metadata, or trace provider fields change, update tests/test_episode.py. It asserts PentestGPT trace files and the wrapper's SQLite run monitor can coexist for one episode, including the stable<pentest-run-id>--<episode-id>identity and metadata fields documented in README.md.
Risks
- pentestgpt_agent/…/test_dependency.py exists because running Python from the repository root can otherwise import an obsolete
unified_agent/copy instead of the installed external dependency. If package commands or CI run from the wrong directory without this guard, provider behavior can silently diverge from the pinnedunified-agent==0.3.0contract in pyproject.toml and uv.lock. - pentestgpt_agent/…/test_local_model.py is intentionally skipped unless
PENTESTGPT_AGENT_LIVE=1, and README.md warns that it spends provider tokens. Treat failures there differently from scripted-suite failures: they may reflect provider credentials, model policy, or backend availability rather than deterministic package regressions. - pentestgpt_agent/HTB_ENIGMA_QUALIFICATION_20260712.md records repeated live-run validation and controller-convergence failures, including safety blocks, invalid evidence handling, oversized quotes, and same-task paraphrase recovery. If changes touch Supervisor selection prompts or bounded retrieval semantics, rerun local multi-stage assertions before interpreting any new HTB-style live result as a qualification.