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.

SampleELF, PE or APK,untrusted bytesHost parsehashes, layout, header,read by SwarmLabRE itselfTools containerno network; Ghidra and jadxwrite the files agents readAgents containerno network; up to six roles,each posts with swarm-postBoardchecks every post andgives it an evidence levelModel gatepins sampling, adds thekey, records every requestModelan endpoint, a mockor a recordingReportsfixed templates overchecked factsSealed runinputs, events, trace anda manifest of SHA-256 hashesReplayoffline: compares every filewith the manifestpostsrequests SampleELF, PE or APK, untrusted bytesHost parsehashes, layout, header, read by SwarmLabRE itselfTools containerno network; Ghidra and jadx write the files agents readAgents containerno network; up to six roles, each posts with swarm-postBoardchecks every post andgives it an evidence levelModel gatepins sampling, adds thekey, records every requestModelan endpoint, a mockor a recordingReportsfixed templates overchecked factsSealed runinputs, events, trace anda manifest of SHA-256 hashesReplayoffline: compares every filewith the manifestpostsrequests
Where each part runs. The sample and the model are untrusted and drawn with a red outline; a dotted outline is a container with no network, a read-only root and all capabilities dropped.

The parts#

PartWhereWhat it does
Host parse (report.py, swarms.py)hostReads 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 noneGhidra (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 noneThe 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)hostA 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)hostWhere the answers come from: an OpenAI-compatible endpoint (OpenAICompat), a scripted Mock, or a recorded run.
Board (swarms.py, class Board)hostTakes 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)hostBuild 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)hostswarmlabre 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)hostA 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#

SourceTrustedWhat happens to it
The sample's bytesnoThey 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 textnoThe 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, reanoIt 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 answernoIt 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 templatesyesA 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#

ModuleWhat it holds
swarmlabre/__init__.pythe version number
swarmlabre/__main__.pymakes python3 -m swarmlabre run the command line
swarmlabre/attack.pyMITRE ATT&CK lookups over data/attack.json
swarmlabre/cli.pythe commands
swarmlabre/client.pythe model clients: an OpenAI-compatible endpoint, a scripted mock, and a recorded run
swarmlabre/clock.pythe one place the time stamped on findings, events and reports is read, so that a replay can pin it
swarmlabre/config.pythe one TOML file, which is only read
swarmlabre/corpus.pythe generated benign samples
swarmlabre/demo.pythe demo sample and the mock model's script
swarmlabre/export.pythe indicator exports: CSV, STIX 2.1 and MISP
swarmlabre/gate.pythe model gate on a Unix socket
swarmlabre/htmlreport.pythe standalone report.html
swarmlabre/player.pyreplay mode of the web UI
swarmlabre/prep_script.pythe preparing step, which runs in the tools container
swarmlabre/replay.pyoffline replay of a recorded run and the bundle export
swarmlabre/report.pythe facts read from the sample, the marking and the checked assessment
swarmlabre/reportschema.pythe validator of report.json
swarmlabre/sandbox.pythe hardened docker run and its checks
swarmlabre/server.pythe web server, the token and the routes' dispatch
swarmlabre/services.pythe services a run needs, as one namespace
swarmlabre/swarms.pythe run, the board and the routes
swarmlabre/text.pythe Reporter's fixed sections and the lint over its prose
swarmlabre/textutil.pythe cleaning of untrusted text and the hiding of secrets in log strings
swarmlabre/yara.pyYARA rules written from byte-checked strings and matched against the sample
FolderWhat 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_NOFOLLOW and 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