š AI-INSTRUCTIONS.md
Defines the architecture, component responsibilities, and development rules for an academic malware sandbox prototype.
What this file does
Defines the architecture, component responsibilities, and development rules for an academic malware sandbox prototype.
When to use it
- Onboarding new developers to the IsoLens project
- Enforcing architectural boundaries and testing policies during development
- Guiding AI code generation to stay within project constraints
- Documenting the multi-agent analysis pipeline and API gateway rules
Assumes this stack
š AI-INSTRUCTIONS.md
# AI Development Instructions ā IsoLens
## š Project Overview
IsoLens is a lightweight academic malware sandbox prototype designed to execute suspicious files inside an isolated virtual machine and generate structured behavioral analysis reports.
The system is modular, extensible, and intentionally simple. It is not production-grade and should not be over-engineered.
The architecture is organized under the `core/` directory to maintain logical separation between system layers.
---
# š Project Structure
. āāā core/ ā āāā agent/ ā āāā controller/ ā āāā gateway/ ā āāā interface/ ā āāā modules/ ā āāā observer/ ā āāā storage/ ā ā āāā database/ ā ā āāā logs/ ā ā āāā reports/ ā ā āāā samples/ ā āāā threatintelligence/ āāā docs/ ā āāā ARCHITECTURE.md ā āāā IDEA.md āāā SandboxShare/ āāā README.md āāā LICENSE āāā CONTRIBUTING.md
---
# š Component Responsibilities
## `core/interface/`
Handles all user-facing logic:
- File upload UI
- Report display
- Risk score visualization
- Screenshot rendering
- Next.js application (App Router) for the web interface
No VM or analysis logic must exist here.
---
## `core/gateway/`
System entry layer:
- API endpoints
- Request validation
- Routes requests to controller
- Returns results to interface
Acts as the communication bridge between UI and system core.
---
## `core/controller/`
Central workflow coordinator:
- Restore VM snapshot
- Start / stop VM
- Inject file into VM
- Trigger execution
- Call observer
- Collect logs
- Call modules
- Call threatintelligence
- Store results
- **VBoxManage screenshot capture** during analysis execution
This is the orchestration brain of IsoLens.
---
## `core/modules/`
Functional processing layer.
Contains expandable submodules such as:
- Log parsing
- IOC extraction
- Risk scoring
- YARA rule generation
- Pattern detection utilities
- VBoxManage output parsing
This layer converts raw monitoring data into structured findings.
This folder is intentionally named "modules" to allow future expansion without structural refactoring.
---
## `core/observer/`
Behavioral monitoring layer:
- Process tracking
- Network monitoring
- File system monitoring
- Registry observation
- Screenshot capture
- Sysmon log extraction
Each monitoring mechanism may exist as its own submodule.
This layer only collects data ā it does not interpret it.
---
## `core/agent/`
Guest-side HTTP service (`isolens_agent.py`) that runs inside the sandbox VM.
- Single-file, stdlib-only Python script (no pip dependencies)
- HTTP API on the host-only network for receiving commands from the controller
- Pluggable collector architecture (Sysmon, Procmon, network, FakeNet, screenshots, handle, tcpvcon)
- Copies samples from VirtualBox shared folder, executes them via `schtasks /it` (interactive session), collects artifacts
- Active screenshot capture using PowerShell + System.Drawing (also captured from host via VBoxManage)
- Packages results as a zip and exports back to SandboxShare for host pickup
- Thread-safe: execution runs in background thread, HTTP stays responsive
API endpoints:
- `GET /api/status` ā health check and agent state
- `GET /api/collectors` ā list available collectors
- `GET /api/artifacts` ā list collected artifact files
- `POST /api/execute` ā execute a sample `{"filename": "...", "timeout": 60, "screenshot_interval": 5}`
- `POST /api/collect` ā run collectors without executing
- `POST /api/cleanup` ā remove all artifacts
- `POST /api/shutdown` ā graceful shutdown
---
## `core/threatintelligence/`
AI-assisted intelligence layer:
- Natural language summaries
- Threat classification
- Risk scoring (0-100 scale with threat level mapping)
- Intelligence enrichment
- AI-driven report augmentation
- MITRE ATT&CK technique mapping
- IOC extraction and deduplication
All AI calls are pinned to the **gpt-5-mini** model for consistent behavior and lower token costs.
### Multi-Agent Analysis Pipeline
The pipeline uses specialised per-tool agents that each receive minimal data (reducing token usage) and return structured XML:
| Agent | Input | Purpose |
|---|---|---|
| `sysmon-analyzer` | Sysmon event summary | Detect process injection, LOLBin abuse, persistence |
| `procmon-analyzer` | Procmon summary JSON | Detect file/registry/process suspicious activity |
| `network-analyzer` | Network capture summary | Detect C2, beaconing, exfiltration |
| `handle-analyzer` | Handle snapshot text | Detect mutex, sensitive file handles |
| `tcpvcon-analyzer` | TCPVcon CSV snapshot | Detect active malicious connections |
| `metadata-analyzer` | Execution metadata | Detect sandbox evasion, anomalies |
| `threat-summarizer` | All per-tool XMLs | Final risk score, classification, MITRE mapping |
### Files
- `copilot_agents.py` ā Per-tool analyst agents + threat-summarizer with XML schema contracts
- `copilot_service.py` ā Async Copilot SDK wrapper (gpt-5-mini enforced)
- `copilot_cli.py` ā CLI for auth-status, list-agents, list-models, chat
- `threat_analyzer.py` ā Pipeline orchestrator: loads report data ā dispatches to agents ā collects XML ā calls summarizer ā saves results
### Gateway Endpoints
- `POST /api/analysis/report/{id}/ai-analyze` ā Run AI analysis pipeline
- `GET /api/analysis/report/{id}/ai-report` ā Retrieve saved AI report
This layer operates on structured findings from collector artifacts, not raw logs.
---
## `core/storage/`
Persistent storage layer.
### Subdirectories:
- `database/` ā SQLite or structured data store
- `samples/` ā Uploaded suspicious files
- `logs/` ā Raw execution logs
- `reports/` ā Final analysis outputs
No business logic must exist here.
---
# š¤ AI Development Rules
These rules must always be followed when generating or modifying code.
---
## 1ļøā£ Architecture Update Rule
When adding:
- New features
- New modules
- Workflow changes
- Structural modifications
The AI MUST:
- Update this `AI-INSTRUCTIONS.md` (Note: `AGENTS.md` is the source of truth, run `python3 scripts/sync_ai_docs.py` after updating)
- Update `docs/ARCHITECTURE.md` if needed
- Reflect changes in component responsibility sections
Never allow architecture drift.
---
## 1ļøā£b Versioning Rule
- Do not version bump for every change. Only bump when the change is meaningful enough to warrant a new version.
- The `/version` endpoint is only updated when API behavior or API contracts change.
- For non-API changes that still warrant a release, do not bump the API version; instead, create a new commit and apply the appropriate version tag.
---
## 1ļøā£c Documentation Sync Rule
When API endpoints are added, removed, or modified, `docs/curls.md` must be updated to match.
---
## 2ļøā£ Mandatory Testing Policy
After ANY code change:
1. Ensure a `tests/` directory exists at project root.
2. Each test must be a standalone script.
3. Naming format:
TEST*{number}*{short_description}.py
Example:
TEST_01_controller_flow.py TEST_02_log_parsing.py TEST_03_risk_scoring.py
Each test script must:
- Run independently
- Print PASS or FAIL
- Print what the test is about
- Print the raw output produced by the test
Example:
[TEST_01_controller_flow] PASS About: Controller dry-run builds correct VBoxManage command Output: {"cmd": ["VBoxManage", "startvm", "TestVM", "--type", "headless"], "returncode": 0, "stdout": "", "stderr": ""}
or
[TEST_02_log_parsing] FAIL About: Network events parsed from sample log Reason: No network events parsed Output: <raw parser output here>
---
## 3ļøā£ Mandatory Test Execution Rule
After implementing a feature:
- Run all tests.
- If ANY test fails:
- Fix the issue.
- Re-run tests.
- Repeat until all tests pass.
Never stop after a failed test.
---
## 4ļøā£ Dependency Management
- Always update `requirements.txt` when new libraries are added.
- Prefer maintained and stable packages.
- Avoid deprecated APIs.
- Keep dependencies minimal.
---
## 5ļøā£ Git Safety & Hygiene
Always ensure:
- Sensitive files are ignored.
- Large binaries are ignored.
- Logs are ignored.
- Databases are ignored.
- VM artifacts are ignored.
- `.env` files are ignored.
Ensure `.gitignore` includes:
core/storage/logs/ core/storage/samples/ core/storage/database/ _.vdi _.iso .env pycache/
Never commit sensitive or large artifacts.
---
## 6ļøā£ Separation of Concerns Rule
- No VM logic outside `controller/`
- No AI logic outside `threatintelligence/`
- No parsing logic outside `modules/`
- No monitoring logic outside `observer/`
- No storage logic outside `storage/`
- No UI logic outside `interface/`
Maintain clean boundaries.
---
## 7ļøā£ Development Philosophy
IsoLens is:
- Academic
- Modular
- Lightweight
- Expandable
- Educational
Do not:
- Introduce microservices
- Add unnecessary abstraction
- Add heavy infrastructure
- Overcomplicate logic
Keep it readable and structured.
---
# š API Gateway Rules
- All API endpoints must be under `/api/`.
- VM identifiers must be passed in the request body for POST endpoints, not in the URL path.
- Request and response schemas must remain consistent and documented via models.
- Gateway routes must be organized into multiple modules (e.g., `system_routes.py`, `controller_routes.py`) and included in `app.py` via routers. Do not define all endpoints directly in `app.py`.
- Maintain `docs/curls.md` with short descriptions and curl examples for all endpoints.
- In `docs/curls.md`, use `dry_run=false` and `raise_on_error=true` in all examples.
# š Final AI Checklist Before Completing Work
Before finalizing any change:
ā Update AI-INSTRUCTIONS.md if architecture changed
ā Update docs/ARCHITECTURE.md if needed
ā Add isolated test scripts
ā Run all tests
ā Ensure all tests PASS
ā Update requirements.txt if required
ā Verify .gitignore safety
No exceptions.
What's inside
14 sections covering project structure, 8 component responsibilities, 7 development rules, and API gateway rules.
Change this for your project
- Replace
gpt-5-miniwith your chosen AI model - Replace
psychoSherlock/Isolenswith your repository name - Replace
core/storage/logs/paths in.gitignore with your own storage paths
Where it goes
Save in docs/ or the repository root. Gives agents and new contributors a map of the codebase.
Worth borrowing
- Multi-agent analysis pipeline with per-tool agents returning structured XML
- Mandatory standalone test scripts with PASS/FAIL output and raw output display
- Separation of concerns enforced by directory boundaries and explicit rules
Related Documents
PCB Design Sources for Industry-Scale Testing
Lists GitHub repos and communities where you can download real PCB designs for testing optimization at scale.
Design Document: BharatSeva AI
Describes a 10-agent AWS system that helps India's informal workers access government schemes via voice-first, serverless architecture.
OpenClaw Enterprise Transformation Plan
Transforms a single-user AI agent into a dual-mode platform supporting both viral open-source and Fortune 500 enterprise deployments through phased security, IAM, audit, multi-tenancy, and Kubernetes features.
Qwen Image and Edit: Open-sourcing and Local GGUF Generations with Lightning
Documents the Qwen-Image and Qwen-Image-Edit models, covering architecture, training, benchmarks, ComfyUI setup, and prompting techniques for local GGUF deployment.