Lab 3A: Windows Firewall DNS Telemetry Triage Refactoring
Module: Module 3: Agentic IDEs & AI Pair Programming
Target Environment: Windows, macOS, or Linux (Workstation, VM, or Container Sandbox) with Antigravity IDE
Estimated Completion Time: 45 Minutes
- Lab 3A: Windows Firewall DNS Telemetry Triage Refactoring
Lab Objectives
- Operate in Read-Only Planning Mode: Audit a fragile legacy Python log triage script (
legacy_log_triage.py) without modifying any source files or running destructive write tools. - Author and Review Architectural Plans: Inspect and approve an agent-generated
implementation_plan.mdartifact detailing proposed structural changes, typed dataclasses, and verification strategies. - Supervise Autonomous Execution: Transition the agent into Execution Mode to implement atomic code replacements (
replace_file_content) and modernize the parser. - Observe Automated Self-Correction: Watch the agent execute the script in the terminal (
python legacy_log_triage.py sample_pfirewall.log), inspect the failure/output, formulate fixes, and iterate autonomously until all unauthorized DNS queries are correctly identified and alerted. - Inspect the Walkthrough Deliverable: Review the finalized
walkthrough.mdreport containing verification evidence and passing execution logs.
Scenario Overview
You have assumed the role of a Systems Administrator / SOC Analyst inheriting a fragile, monolithic Python script (legacy_log_triage.py) used by your operations team to parse Windows Defender Firewall logs (pfirewall.log) and flag suspicious network connections.
Your organization enforces a strict internal DNS policy:
- Outbound DNS resolution must route only to authorized baseline resolvers:
8.8.8.8over UDP/53 (governed by RFC 1035) and TCP/53 (per RFC 7766). - Outbound queries directed to unauthorized resolvers (such as
8.8.4.4over UDP/53 or TCP/53) represent unauthorized resolver usage, policy violations, or potential DNS exfiltration, and must trigger a triage alert.
The script currently functions under narrow conditions, but suffers from severe technical debt:
- Brittle Tokenization: It uses naive whitespace splitting (
line.split(" ")) and hardcoded list indices instead of typed schemas. - Header Comment Crashes: It crashes immediately when encountering W3C header comments starting with
#(#Version: 1.5,#Fields:). - Bare Exception Handling: It relies on a bare
except:block that masks syntax errors, missing files, and permission exceptions. - Incomplete Triage Logic: It blindly checks only for
DROPactions, completely failing to detect allowed outbound traffic to unauthorized DNS destinations (such as8.8.4.4:53).
You will use Antigravity IDE’s Planning Mode to audit the codebase, author an implementation_plan.md, approve the refactoring blueprint, supervise the agent as it autonomously refactors the script and resolves execution failures, and inspect the resulting walkthrough.md.
[!NOTE] Operational Guidance: Understanding Tool Access, Sandboxes & Autonomy
Security boundaries in agentic engineering are never purely black and white: they depend entirely on understanding what tools your agent possesses and what filesystem or network access is actually granted.
- Know Your Access Boundaries: Running inside Windows Subsystem for Linux (WSL) keeps package dependencies organized, but remember that WSL mounts host drives (
/mnt/c/) and shares host network routes by default. Similarly, tools like Hermes or Docker containers offer dedicated sandbox modes right on your local machine, but they are only as effective as the bind mounts and environment variables you configure. Always verify what directories, ports, and credentials an agent can touch before letting it run.- Calibrate Autonomy with Familiarity: There is certainly a place for fully autonomous solutions, but that level of trust comes only with hands-on familiarity that this course is designed to build. When starting out with new agentic harnesses or models, keep the Human-in-the-Loop permission gate active. Review proposed terminal commands and atomic diffs rather than blindly auto-approving them.
- Defensive Operational Habits: Whether you pair with an agent directly on bare metal or inside an isolated Virtual Machine (VM), build defensive muscle memory: work in dedicated git scratch branches so any bad change can be reverted instantly, keep secrets (
.env, private keys) quarantined away from project folders, and test new agentic skills in clean, low-stakes workspaces first.
Starter Files
The lab files are staged in this directory:
legacy_log_triage.py: The legacy log triage script.sample_pfirewall.log: Bundled sample Windows Firewall log containing standard header comments, normal traffic, dropped packets, and the 4 DNS test combinations.
Step-by-Step Execution Guide
Step 1: Stage the Legacy Workspace in Your Sandbox
You can complete this lab using either the pre-packaged sample log or live-captured firewall logs:
Option A: Bundled Sample Log (Instant / Cross-Platform)
Use the included sample_pfirewall.log. This option requires no administrative privileges and works immediately across Windows, macOS, Linux, and WSL environments.
If working inside this repository, navigate directly to this lab directory:
cd genai-for-tinkerers/labs/module3/lab3a
Alternatively, copy the lab directory to an isolated sandbox:
mkdir -p ~/labs/lab3a-refactoring
cp sample_pfirewall.log legacy_log_triage.py ~/labs/lab3a-refactoring/
cd ~/labs/lab3a-refactoring
[!WARNING] The Golden Rule of Agentic Engineering: ALWAYS MAKE A BACKUP!
Notice that in this lab, we dive straight into letting the agent refactorlegacy_log_triage.pyin-place. If you didn’t create a backup copy before starting… your only backup is whatever code is published on this lab website!
In any real-world project, never let an agent perform in-place edits on uncommitted files without a backup or a clean git branch. Always rungit checkout -b feature/triage-refactoror make a manual copy (cp legacy_log_triage.py legacy_log_triage.py.bak) so you have an instant rollback safety net if an autonomous edit goes sideways.
Option B: Live Capture on Windows (PowerShell / CMD & nslookup)
If you are working on a native Windows machine (or Windows on ARM / VM) and wish to generate authentic firewall logs:
- Enable Windows Firewall Logging (Run PowerShell as Administrator):
Set-NetFirewallProfile -Profile Domain,Public,Private -LogAllowed True -LogBlocked True -LogFileName "$env:SystemRoot\System32\LogFiles\Firewall\pfirewall.log"(Or via Command Prompt as Administrator:
netsh advfirewall set allprofiles logging allowedconnections enableandnetsh advfirewall set allprofiles logging droppedconnections enable) -
Generate the 4 DNS Test Combinations: Open PowerShell or Command Prompt and execute queries against both resolvers across both UDP and TCP:
In PowerShell:
# 1. Authorized DNS Query (UDP/53 baseline) nslookup google.com 8.8.8.8 # 2. Authorized DNS Query over TCP (TCP/53 virtual circuit) nslookup -vc google.com 8.8.8.8 # 3. Unauthorized DNS Query (UDP/53 alert condition) nslookup google.com 8.8.4.4 # 4. Unauthorized DNS Query over TCP (TCP/53 virtual circuit alert condition) nslookup -vc google.com 8.8.4.4Or in Command Prompt (CMD):
:: 1. Authorized DNS Query (UDP/53 baseline) nslookup google.com 8.8.8.8 :: 2. Authorized DNS Query over TCP (TCP/53 virtual circuit) nslookup -vc google.com 8.8.8.8 :: 3. Unauthorized DNS Query (UDP/53 alert condition) nslookup google.com 8.8.4.4 :: 4. Unauthorized DNS Query over TCP (TCP/53 virtual circuit alert condition) nslookup -vc google.com 8.8.4.4 -
Copy the Generated Log: Copy the log file into your lab directory:
From PowerShell (Administrator):
Copy-Item "$env:SystemRoot\System32\LogFiles\Firewall\pfirewall.log" .\sample_pfirewall.logFrom Command Prompt (Administrator):
copy "%SystemRoot%\System32\LogFiles\Firewall\pfirewall.log" .\sample_pfirewall.log
(Note: Students on macOS or Linux can stand up a Windows on ARM virtual machine to capture these logs, or simply rely on Option A.)
Baseline Verification
Run the legacy script directly against the sample log to observe its failure:
python legacy_log_triage.py sample_pfirewall.log
Observe the console output:
An error occurred reading logs
Flagged 0 suspicious entries.

Why did it fail?
The legacy script uses naive whitespace splitting (line.split(" ")) and hardcoded column indices (parts[6]). When it reaches the W3C header comments (#Version: 1.5, #Fields:), it raises an unhandled IndexError. The bare except: block masks the exception and prints an error message, returning zero flagged entries and completely missing the unauthorized queries to 8.8.4.4:53!
Step 2: Engage Planning Mode & Collaborative Interview (/plan & /grill-me)
- Launch Antigravity CLI (
agy) inside your lab directory (or open the folder in Antigravity IDE). When prompted, select> Yes, I trust this folderto grant workspace access:

- In the interface, switch to Planning Mode. In the AGY CLI, you can activate Planning Mode either by typing the slash command
/planor by pressingShift+Tabto cycle through modes (which displaysPlan mode: research & plan onlyand sets theplanbadge):


- Issue the concise refactoring prompt with
/grill-me:/plan /grill-me Audit legacy_log_triage.py. It fails when running against sample_pfirewall.log. I want to refactor it to handle Windows Firewall logs and flag unauthorized DNS queries. - The Human-in-the-Loop Safety Gate (Terminal Permission Options):
As the agent begins inspecting your workspace, it will request permission before executing any terminal command (such as
cmd.exe /c "dir /b"to check what files exist):

You are presented with 4 permission levels:
1. Yes, run command(Single-Use Approval): Authorizes only this specific command execution. If the agent runs the command again, it will pause and prompt for permission. Ideal for one-off or unfamiliar commands.2. Yes, and always allow in this conversation for commands that start with '...'(Session Allowlist): Authorizes this command and auto-approves any future command in this active session matching that prefix without saving permanent changes. Ideal for repetitive read-only inspections.3. Yes, and always allow for commands that start with '...' (Persist to settings.json)(Permanent Allowlist): Authorizes the command and writes a persistent allowlist rule to your configuration file (settings.json), auto-approving matching commands in all future sessions.4. No, cancel(Deny / Abort): Blocks command execution and informs the agent that the action was rejected, causing it to pivot to an alternative approach.
(For harmless inspection commands like dir /b, choose 1 or 2 to allow the agent to proceed.)
- Participate in the
/grill-meInterview: Instead of requiring you to write a massive, 20-line specification upfront, the/grill-meworkflow flips the dynamic: the agent presents interactive multiple-choice questions directly in your terminal to establish architectural requirements one decision at a time:

[!NOTE] Sequential Decision Walk: The agent will walk down each branch of the design tree one question at a time. You may receive several sequential question prompts covering policy strictness, data schemas, comment skipping, and error handling. Use the decision criteria below as your guide:
- DNS Alerting Rules: When prompted on policy strictness, select
1. (Recommended) Allowlist-based rule: treat 8.8.8.8 as authorized and flag any outbound port 53 query (UDP/TCP) to any other destination (such as 8.8.4.4)(or Option 2 targeting8.8.4.4directly). - Data Model: When asked about schemas, choose: Use Python standard library
dataclass FirewallEntrywith typed scalar fields. - Header Comments: When asked how to handle comment lines starting with
#, specify: Gracefully skip comment lines (#Version, #Fields) without raising exceptions. - Error Handling: When asked about exceptions, choose: Eliminate bare
except:blocks, use context managers (with open), and handleFileNotFoundErrorexplicitly. - Dependencies: When asked about third-party packages, specify: Use only Python standard libraries without external dependencies.
- Generate the Implementation Plan:
Once you and the agent reach a shared understanding through the interview, the agent synthesizes your answers into a structured
implementation_plan.mdartifact detailing the proposed dataclass, triage rules, and verification plan, without modifying any source files yet.
Step 3: Human Review & Architectural Sign-Off
- Access and Review the Implementation Plan:
When the agent finishes authoring the plan, it alerts you with
1 artifact · /artifact to review. You have two convenient ways to inspect it:- Option A: CLI TUI Review (
/artifact): Type/artifactin the prompt (or presspto preview /open) to review the plan interactively directly inside the terminal. - Option B: Direct Filepath: Open the absolute path printed in the agent’s turn (
~/.gemini/antigravity-cli/brain/<conversation-id>/implementation_plan.md) in your editor of choice.
- Option A: CLI TUI Review (

When opened in the TUI, the plan renders with syntax highlighting, line numbers, and interactive keyboard controls:

- Inline Comments (
c): If you wish to leave targeted feedback or request adjustments on a specific section, presscon any line to add a comment. - Return to Menu (
esc): Once satisfied with the plan, pressescto close the preview and return to the artifact action menu.
- Verify Architectural Compliance:
Confirm that the plan reflects the decisions agreed upon during the
/grill-meinterview:- Proposed Changes:
[MODIFY] legacy_log_triage.py. - Schema Design: Clean typed structure (
dataclass FirewallEntry). - Triage Rules: Outbound port 53 traffic to
8.8.4.4flagged as alerts for both UDP and TCP. - Verification Plan: Running
python legacy_log_triage.py sample_pfirewall.logto verify flagged alerts.
- Proposed Changes:
- Approve and Transition to Execution Mode:
In the
/artifactTUI menu, selectapprove(or pressy/Shift+Ato approve all), or enter the approval prompt in chat:The implementation plan is approved. Proceed to Execution Mode and implement all changes.
Step 4: Autonomous Execution & Test Verification
-
Observe the Transition to Execution: The agent shifts into execution mode to implement the modernized architecture.
-
Inspect and Accept the Atomic Diff: The agent presents a color-coded atomic diff preview (
+101 -33) displaying deleted lines (red) and additions (green), including the typed@dataclass class FirewallEntry:,AUTHORIZED_DNS_SERVERS, and robust parsing logic:

- Manual Diff Review: Inspect the line changes and select
> 1. Yes, accept this change(or pressfto view the full diff). - Auto-Approve Edits (
Shift+Tab): If you want to allow the agent to apply code changes directly without stopping to prompt for every individual file diff, pressShift+Tabto cycle intoaccept-editsmode:

- Autonomous Self-Verification by the Agent:
Notice an essential feature of autonomous agentic loops: immediately after applying the refactor to disk, the agent automatically dispatches a command to test the script against
sample_pfirewall.log:

Select 1. Yes, run command to authorize the agent to execute its self-verification test.
- Observe Output Verification:
The modernized script successfully parses the W3C headers, evaluates each connection against the DNS security baseline, and outputs the flagged policy violations:
[ALERT] Unauthorized DNS Query detected: Timestamp: 2026-09-21 14:05:10 | Protocol: UDP | Source: 192.168.1.100:53103 -> Destination: 8.8.4.4:53 [ALERT] Unauthorized DNS Query detected: Timestamp: 2026-09-21 14:05:12 | Protocol: TCP | Source: 192.168.1.100:53104 -> Destination: 8.8.4.4:53 Flagged 2 suspicious entries.

Notice that both UDP and TCP queries to `8.8.4.4` are flagged, while `8.8.8.8` queries (both UDP and TCP) are recognized as authorized baseline traffic and not alerted. 5. **Automated Self-Correction (If Needed)**: If the agent's first attempt misses TCP queries or mishandles trailing comment lines, observe how the agent reads the execution output, formulates an atomic fix, and re-runs until the triage logic is verified.