Environment:0xSteph Pentest ai agents SQLite or Python3
| Knowledge Sources | |
|---|---|
| Domains | Infrastructure, Security_Testing |
| Last Updated | 2026-10-22 12:00 GMT |
Overview
Lightweight shell-based environment with SQLite3 CLI or Python3's sqlite3 module for zero-token-cost persistent engagement storage.
Description
This environment provides the persistence layer for the pentest-ai findings database. It uses a dual-backend design: if the `sqlite3` CLI binary is available, it is used directly; otherwise, the system falls back to Python3's built-in `sqlite3` module. The database file is stored at `~/.pentest-ai/findings.db` by default. No external server is required — SQLite is an embedded database. The entire layer runs through Bash scripts (`findings.sh`, `handoff.sh`, `migrate.sh`) that source a shared library (`lib/common.sh`) for connection management and SQL escaping.
Usage
Use this environment for any operation involving the Findings Database — creating engagements, adding hosts/services/vulnerabilities/credentials/attack chains, generating handoff reports, or exporting engagement data. It is the mandatory prerequisite for running the Findings_CLI, Db_Common_Library, and Handoff_Report_Generator implementations.
System Requirements
| Category | Requirement | Notes |
|---|---|---|
| OS | Linux, macOS, or WSL | Bash 4.0+ required for associative arrays |
| Hardware | Any | No GPU or special hardware needed; minimal disk for SQLite file |
| Disk | < 50MB | SQLite database file grows with engagement data; negligible for typical engagements |
Dependencies
System Packages
- `bash` >= 4.0 (associative arrays in doctor.sh, `set -euo pipefail`)
- `sqlite3` (preferred CLI backend; if absent, Python3 fallback is used)
- `python3` >= 3.6 (fallback backend; must include built-in `sqlite3` module)
Python Packages
- `sqlite3` (standard library — no pip install needed)
Credentials
The following environment variables configure the database layer (none are secrets):
- `PENTEST_AI_HOME`: Data directory (default: `~/.pentest-ai`)
- `PENTEST_AI_DB`: Database file path (default: `$PENTEST_AI_HOME/findings.db`)
- `PENTEST_AI_ENGAGEMENT`: Active engagement ID (default: `default`)
No API keys or tokens are required for this environment.
Quick Install
# Debian/Ubuntu: install sqlite3 and python3
sudo apt-get install -y sqlite3 python3
# macOS: sqlite3 ships with the OS; python3 via brew
brew install python3
# Verify both backends
sqlite3 --version
python3 -c "import sqlite3; print(sqlite3.sqlite_version)"
Code Evidence
Dual-backend detection from `db/lib/common.sh:20-31`:
check_sqlite() {
if command -v sqlite3 &>/dev/null; then
USE_PYTHON_SQLITE=false
elif python3 -c "import sqlite3" &>/dev/null; then
USE_PYTHON_SQLITE=true
else
echo "Error: sqlite3 is required. Install with:" >&2
echo " sudo apt install sqlite3 (Debian/Ubuntu)" >&2
echo " brew install sqlite (macOS)" >&2
exit 1
fi
}
# Detect sqlite backend at source time
check_sqlite
Environment variable configuration from `db/lib/common.sh:6-8`:
DB_DIR="${PENTEST_AI_HOME:-$HOME/.pentest-ai}"
DB_PATH="${PENTEST_AI_DB:-$DB_DIR/findings.db}"
ENGAGEMENT="${PENTEST_AI_ENGAGEMENT:-default}"
Python3 fallback execution from `db/lib/common.sh:36-70`:
_py_sqlite() {
local mode="${1:-tab}"
local sql="${2:-}"
python3 -c "
import sqlite3, sys, json
conn = sqlite3.connect('$DB_PATH')
conn.execute('PRAGMA foreign_keys=ON')
cur = conn.cursor()
try:
cur.execute('''$sql''')
...
conn.close()
"
}
Common Errors
| Error Message | Cause | Solution |
|---|---|---|
| `Error: sqlite3 is required.` | Neither `sqlite3` CLI nor Python3 `sqlite3` module found | Install `sqlite3` or `python3` (see Quick Install) |
| `Error: Engagement 'X' not found.` | `PENTEST_AI_ENGAGEMENT` set to a non-existent ID | Run `findings.sh init <id>` first, then `findings.sh use <id>` |
| `bash: associative array: bad array subscript` | Bash version < 4.0 (macOS default bash 3.2) | Upgrade bash via `brew install bash` or use Linux/WSL |
| `no such table: engagements` | Database file exists but schema not loaded | Run `db/migrate.sh` or delete the `.db` file and let `ensure_db` recreate it |
Compatibility Notes
- macOS default bash: macOS ships bash 3.2 which lacks associative arrays used in `doctor.sh`. Install bash 4+ via Homebrew (`brew install bash`) or use the Python3 fallback for DB operations only.
- sqlite3 CLI vs Python3: The CLI backend is preferred for performance (no interpreter startup overhead per query). The Python3 fallback works identically but is slightly slower due to Python process spawn cost per query.
- Database file location: Overridable via `PENTEST_AI_DB` env var. Useful for storing engagements on a shared drive or in a project-specific directory.
- Foreign keys: The Python3 backend explicitly enables `PRAGMA foreign_keys=ON`. The sqlite3 CLI backend relies on SQLite's default (OFF by default in older versions). Schema uses `INSERT OR REPLACE` and `INSERT OR IGNORE` to avoid most FK issues.