Python Virtual Environments Cheat Sheet
Updated August 4, 2026 · Written by PWNMI — see About.
A virtual environment is a self-contained Python install — its own site-packages, isolated from the system Python and from any other venv — created with the standard library's own venv module, no separate install required. On this site it's the fix for pip install failing with error: externally-managed-environment on Kali and every other modern Debian-based distro, which several CVE labs run into the moment they clone a public exploit's requirements.txt. For everything else python3 is used for on an engagement — reverse shells, TTY upgrades, running the exploit script this venv is isolating — see the python3 cheat sheet.
Red Team / Offensive Use
Two unrelated public exploit scripts pinning incompatible versions of the same library — one needs requests==2.28, the other needs requests>=2.31 — is a routine annoyance on a real engagement toolbox that's accumulated a year of one-off PoCs. A venv per tool sidesteps the conflict entirely instead of fighting it with pip install --force. It's also basic hygiene on a shared or team-provisioned attack box: a one-off exploit's dependencies live in its own venv/ folder and get deleted with it, instead of permanently altering the box's global Python for everyone who uses it after you. And since PEP 668 (Debian Bookworm, Kali rolling, Ubuntu 23.04+), it's not optional at all — pip install against system Python is blocked by default, full stop.
Worth being precise about what a venv actually isolates, though: it's dependency isolation, not a security sandbox. It doesn't restrict what a script can do once it's running — a malicious or booby-trapped PoC has the same filesystem and network access inside a venv as outside one. If you don't trust a PoC's code, run it in a disposable container or VM (see the Docker cheatsheet), not just a venv.
Established Cheatsheet
Python docs: venv — the official standard-library reference.
PWNMI's Top 7 Use Cases
python3 -m venv venv— create a new virtual environment in avenv/folder; the fix forexternally-managed-environmenton Kali and any modern Debian-based distrosource venv/bin/activate— activate it in the current shell; everypip installandpython3after this point runs inside the isolated environment, not system Pythonpip install -r requirements.txt— install a PoC or tool's exact pinned dependencies into the active venv, isolated from every other tool's requirementsdeactivate— leave the environment, back to system Python, without deleting anythingvenv/bin/python3 exploit.py— run a script inside the venv without activating first, useful in a one-liner or a non-interactive scriptpip freeze > requirements.txt— snapshot exactly what's installed; useful for reproducing a specific tool's working state later or documenting exact versions used in a reportpython3 -m venv --system-site-packages venv— create a venv that still sees system-wide packages, useful when a tool needs something heavy already installed viaapt(impacket, for example) alongside its own pinned extras
Next step
To see this used as part of a real exploit chain, see CVE-2026-65008 (Grav CMS), CVE-2025-54068 (Laravel Livewire), or CVE-2025-68613 (n8n) — all three clone a public PoC with its own requirements.txt. For isolating a tool you don't trust at all, not just its dependencies, see Docker for Security Labs.
Get new write-ups in your inbox
New roadmaps, tool walkthroughs, and lab write-ups. No spam. Unsubscribe anytime.