๐ AI-INSTRUCTIONS.md
IsoLens is a lightweight academic malware sandbox prototype designed to execute suspicious files inside an isolated virtual machine and generate structured behavioral analysis reports.
๐ 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.
Related Documents
Design Document: BharatSeva AI
BharatSeva AI is a multi-agent orchestration system built on AWS using Amazon Bedrock Agents with Claude 3.5 Sonnet as the foundation model. The system deploys 10 AI agents (1 Master Orchestrator + 9 Specialist Agents) to assist India's informal sector workers in navigating government schemes across three domains: PM Vishwakarma (artisan credit), PMFBY (crop insurance), and BOCW (construction worker welfare).
OpenClaw Enterprise Transformation Plan
Transform OpenClaw from a single-user personal AI assistant into a **dual-mode platform** that is simultaneously:
Qwen Image and Edit: Open-sourcing and Local GGUF Generations with Lightning
Daniel Sandner, for article on https://sandner.art/
Qwen3-TTS โ Model Reference
Models: `Qwen/Qwen3-TTS-12Hz-0.6B-CustomVoice` and `Qwen/Qwen3-TTS-12Hz-1.7B-CustomVoice`