Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:0xSteph Pentest ai PlaybookRunner execute

From Leeroopedia
Knowledge Sources
Domains Security_Testing, Methodology
Last Updated 2026-10-23 12:00 GMT

Overview

Concrete playbook execution runner that walks planned phases, runs each tool against the target with scope enforcement, and persists findings to the database.

Description

The PlaybookRunner class executes a playbook against a target. It:

  • Validates the target (rejects shell metacharacters)
  • Creates an engagement in FindingsDB (scope="playbook")
  • Plans phases via `plan_phases()`
  • For each non-manual phase, runs each tool through the registry or builtins
  • Enforces scope per request via ScopeEnforcer.check()
  • Persists findings to FindingsDB per tool
  • Supports builtin tools (builtin_http_headers, builtin_ssl_check, etc.) mapped to engine.scanners functions
  • Missing binaries and manual phases are skipped, not faked
  • Finalizes the engagement status on completion

Usage

Import this when you need to:

  • Execute a playbook against a target (`ptai playbook run --execute`)
  • Run methodology phases with tool invocation and scope enforcement

Code Reference

Source Location

  • Repository: pentest-ai
  • File: engine/playbook_runner.py

Signature

class PlaybookRunner:
    def __init__(self, registry: Any, db: Any, scope: ScopeEnforcer | None = None):

    async def execute(
        self,
        playbook: Playbook,
        inputs: dict[str, str],
    ) -> dict[str, Any]:
        """Execute playbook phases. Returns summary dict."""

    async def _run_one(
        self,
        name: str,
        target: str,
        engagement_id: str,
    ) -> list[dict[str, Any]] | None:
        """Run one tool or builtin. Returns findings or None."""

Import

from engine.playbook_runner import PlaybookRunner

I/O Contract

Inputs

Name Type Required Description
playbook Playbook Yes The playbook to execute
inputs dict[str, str] Yes Must contain 'target'; other playbook inputs
registry Any Yes ToolRegistry (constructor)
db Any Yes FindingsDB (constructor)
scope None No Scope enforcement (constructor)

Outputs

Name Type Description
returns playbook, target, engagement_id, status, findings_count, phases_run, phases_skipped, tools_run, tools_skipped

Usage Examples

Executing a Playbook

from engine.playbook import load_playbook
from engine.playbook_runner import PlaybookRunner
from tools.registry import ToolRegistry

pb = load_playbook("playbooks/builtin/web-app-quick.yaml")
runner = PlaybookRunner(ToolRegistry(), db, scope=enforcer)
result = await runner.execute(pb, {"target": "https://app.example.com"})
print(f"Findings: {result['findings_count']}")
print(f"Phases run: {result['phases_run']}")

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment