Docs / Reference / Architecture
Architecture
SwarmLabRE is a Python 3.12 program that uses only the standard library, with no package to install and no build step. Docker is needed only to analyse a new file.
Where each part runs#
A run starts on the host, which parses the sample itself. The tools container prepares the files that the agents read, and the agents container runs the roles. Both containers have no network, and the model reaches the agents only through a gate on the host.
The parts#
| Part | Where | What it does |
|---|---|---|
Host parse (report.py, swarms.py) | host | Reads the sample itself: hashes, header, segments, entropy and the APK manifest. The layout, the regions and the numbers of a report come from here and never from an agent. |
Tools container (swarmlabre-tools) | Docker, --network none | Ghidra (headless), jadx, Apktool and the rea command line read the sample, mounted read-only, once and write the files the agents read: strings, imports, functions and decompiled code. The host adds an ATT&CK lookup table written from MITRE's data. It runs prep_script.py, which is piped in on standard input and never mounted. |
Agents container (swarmlabre-agent) | Docker, --network none | The pi coding agent, with up to six roles, each under its own uid. They read the prepared files, call the tool server through a locked socket and report with skills/rea-swarm/scripts/swarm-post. |
Model gate (gate.py) | host | A Unix-socket HTTP server between the agents and the model. It overwrites temperature and seed in every request, adds the key, limits the requests in flight and records every exchange. |
Model client (client.py) | host | Where the answers come from: an OpenAI-compatible endpoint (OpenAICompat), a scripted Mock, or a recorded run. |
Board (swarms.py, class Board) | host | Takes every post and decides. When the bytes at the offset are the value given, the finding is byte-checked. When every cited tool call exists in the run's tool log and appears in that agent's own session output, it is call-cited. Otherwise it is claimed. The board also checks the ATT&CK id and name, the function, duplicates, the caps per role and per run, and disputes between agents. A refused post is kept with a reason code. |
Report writers (report.py, htmlreport.py, text.py, export.py, yara.py) | host | Build report.html, report.md, report.json, board.json, iocs.csv, iocs.stix.json, iocs.misp.json and detection.yar from checked facts. Sentences about what a finding means are fixed templates, and the Reporter's prose is cut sentence by sentence by a lint and always labelled. A YARA rule is written only from byte-checked strings and matched against the sample by the repository's own matcher before it is shown. |
Replay (replay.py, player.py) | host | swarmlabre replay rebuilds every output from the recorded inputs and compares each file with its SHA-256. player.Replay plays a recording through the web UI. |
Server and UI (server.py, ui/swarms.html) | host | A standard library http.server: one page, a bearer token, loopback only by default, in three modes: live, replay and static. The web UI describes them. |
What is trusted, and what is not#
| Source | Trusted | What happens to it |
|---|---|---|
| The sample's bytes | no | They are read and never executed. Strings from them are made printable, capped, defanged in reports and set in the page as text. |
| What an agent writes: findings, notes and the Reporter's text | no | The board parses it, and a finding enters only through its checks. Prose is linted, capped and labelled as model text, and never put in a notification, a path or a command. |
What a tool prints: Ghidra, jadx, rea | no | It is capped and read as data. The files of the tools container are copied out without extracting any archive and opened with O_NOFOLLOW. |
| The model's answer | no | It is an opinion. The assessment keeps only the fields the board can check, and a model's verdict never changes a count, a level or a hash. |
| The board's own decisions, the host parse, MITRE's table and the fixed templates | yes | A report states these as fact. |
The model's key lives only on the host. The agents container gets the model through the gate's Unix socket, mounted read-only. Security lists the threats and what is not claimed.
Modules#
| Module | What it holds |
|---|---|
swarmlabre/__init__.py | the version number |
swarmlabre/__main__.py | makes python3 -m swarmlabre run the command line |
swarmlabre/attack.py | MITRE ATT&CK lookups over data/attack.json |
swarmlabre/cli.py | the commands |
swarmlabre/client.py | the model clients: an OpenAI-compatible endpoint, a scripted mock, and a recorded run |
swarmlabre/clock.py | the one place the time stamped on findings, events and reports is read, so that a replay can pin it |
swarmlabre/config.py | the one TOML file, which is only read |
swarmlabre/corpus.py | the generated benign samples |
swarmlabre/demo.py | the demo sample and the mock model's script |
swarmlabre/export.py | the indicator exports: CSV, STIX 2.1 and MISP |
swarmlabre/gate.py | the model gate on a Unix socket |
swarmlabre/htmlreport.py | the standalone report.html |
swarmlabre/player.py | replay mode of the web UI |
swarmlabre/prep_script.py | the preparing step, which runs in the tools container |
swarmlabre/replay.py | offline replay of a recorded run and the bundle export |
swarmlabre/report.py | the facts read from the sample, the marking and the checked assessment |
swarmlabre/reportschema.py | the validator of report.json |
swarmlabre/sandbox.py | the hardened docker run and its checks |
swarmlabre/server.py | the web server, the token and the routes' dispatch |
swarmlabre/services.py | the services a run needs, as one namespace |
swarmlabre/swarms.py | the run, the board and the routes |
swarmlabre/text.py | the Reporter's fixed sections and the lint over its prose |
swarmlabre/textutil.py | the cleaning of untrusted text and the hiding of secrets in log strings |
swarmlabre/yara.py | YARA rules written from byte-checked strings and matched against the sample |
| Folder | What it holds |
|---|---|
swarmlabre/data/ | attack.json, the MITRE ATT&CK table |
tools/ | build-demo.py (the static demo), shim.js (the in-page API for it) and build-attack-table.py (rebuilds the ATT&CK table from MITRE's data) |
skills/ | the two skills the agents get: rea-swarm and rea-reverse-engineering |
sandbox/ | the two Dockerfiles, sock-fwd.js and swarmlabre-net-entry |
ui/ | swarms.html, the page of the web UI, and the fonts it uses |
Rules the code keeps#
- The program and the scripts that run inside the containers use the standard library only.
- Files a container can write are untrusted: never extract a tar, resolve paths inside the container, open with
O_NOFOLLOWand cap sizes. - Findings enter only through
swarm-post, and a model's verdict is display-only. - Every JSON body is capped at 1 MiB, and the raw-body routes are routed before the JSON parse.
- The time stamped on findings, events and reports comes from
clock.py, so that a replay can pin it. Other modules read the clock only to measure durations and the age of a cached answer.
SwarmLabRE alpha 0.1.0Edit this page on GitHub