Configuring Visual Studio Code with the Python extension, selecting a virtual-environment interpreter, and debugging security scripts.
VS Code is the most popular free editor for Python and a strong default for security tooling. With Microsoft's Python extension it gains IntelliSense, linting, an integrated debugger, and per-project interpreter selection. The critical setup step for pentest work is pointing VS Code at your project's [[Managing-Virtual-Environments|venv]] so it edits, lints, and runs against the exact dependencies you pinned.
# Install VS Code (Debian/Kali via Microsoft repo already configured, or snap)
sudo apt install -y code # if the Microsoft apt repo is set up
# Install the Python extension from the CLI
code --install-extension ms-python.pythonCore pieces:
- Python extension (
ms-python.python) — language support, interpreter management, test/debug integration. Pulls in Pylance for fast IntelliSense. - Interpreter selection —
Ctrl+Shift+P-> "Python: Select Interpreter". Choose the.venv/bin/pythoninside your project. - Workspace settings — stored in
.vscode/settings.json, committed with the project so the whole team gets the same interpreter and lint config. - Debugger — configured in
.vscode/launch.json; set breakpoints in the gutter and inspect variables live.
// .vscode/settings.json — pin the venv and enable linting
{
"python.defaultInterpreterPath": "${workspaceFolder}/.venv/bin/python",
"python.terminal.activateEnvironment": true,
"python.analysis.typeCheckingMode": "basic"
}// .vscode/launch.json — debug the current file with arguments
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "debugpy",
"request": "launch",
"program": "${file}",
"args": ["--target", "10.10.10.5"],
"console": "integratedTerminal"
}
]
}# scanner.py — set a breakpoint on the parsed_port line and step through
import argparse
def main() -> None:
parser = argparse.ArgumentParser()
parser.add_argument("--target", required=True)
args = parser.parse_args()
parsed_port = 443 # breakpoint here, inspect `args`
print(f"Scanning {args.target}:{parsed_port}")
if __name__ == "__main__":
main()Scanning 10.10.10.5:443
- Stepping through an exploit PoC with the debugger to watch a buffer/offset value instead of littering the code with
print(). - Using Remote - SSH to edit and debug tooling directly on a lab jump box while keeping files off your laptop.
- Committing
.vscode/settings.jsonso every operator on an engagement uses the identical pinned interpreter and linter.
- Always run "Python: Select Interpreter" and choose the project venv before editing.
- Enable
python.terminal.activateEnvironmentso the integrated terminal auto-activates the venv. - Turn on a type checker (
basic) to catchbytes/strmix-ups common in network code. - Keep secrets and target lists out of
launch.jsonargsif the repo is shared.
- Editing with the global interpreter selected, so Pylance shows imports as unresolved or resolves the wrong package versions.
- Committing a
launch.jsonthat hardcodes live target IPs or credentials. - Assuming "Run Python File" activates the venv — verify the terminal prompt shows
(.venv).
Goal: debug a script running inside a venv.
python3 -m venv .venv && source .venv/bin/activate && pip install requests.- Open the folder in VS Code, install
ms-python.python, and select the.venvinterpreter. - Create a script that GETs a URL with
requests, set a breakpoint on the response line. - Press F5, step over the request, and inspect the
responseobject in the debugger's Variables pane.
- [[Selecting-an-IDE]]
- [[Managing-Virtual-Environments]]
- [[Pip-Package-Manager]]
- [[Python-Environment-Setup/Readme|Python Environment Setup]] — module index
- [[Readme|Python for Security Professionals]] — course home