Home / Demos / PLC tank controller in Structured Text
Embedded MATIEC iec2c · IEC 61131-3
PLC tank controller in Structured Text
The agent writes a tank fill/drain controller in IEC 61131-3 Structured Text, compiles it with the open MATIEC compiler, links it into a 10 ms scan-cycle harness and runs it against a virtual plant. The judge's rules are numeric: the level never leaves its safe band, the pump never runs dry even when a level switch lies, an emergency stop de-energises every actuator within one scan and latches, and the plant recovers afterwards.
Measured
all
≤ 94 cm design cap
determinism
self-test, ≥ 90 % required
reproduced Independently reproduced from the README alone in a fresh sandbox. Numbers from the demo's README and receipt.
Ask your agent
With the sandbox plugin or any agent that can use a sandbox, paste:
In a sandbox, build the IEC 61131-3 Structured Text tank controller for `cookbook/plc-st` of https://github.com/agent-next/sandbox from scratch. Read `SPEC.md` first, then write your own `tank_ctrl.st` (program + configuration) using the pinned MATIEC toolchain from `judge/setup.sh`. Iterate with `bash judge/selftest.sh` and `bash judge/grade.sh your_tank_ctrl.st --json /tmp/v.json` until the judge passes every gate and your controller is not one of the six known-bad single-edit mutants. Show me the final verdict JSON and the key numbers (max/min level, kill rate). Do not modify anything under `judge/`.Or run it yourself
Creates a sandbox, installs the pinned tools, runs the judge's self-test, grades the known-good example, prints the verdict and kills the sandbox.
pip install "git+https://github.com/agent-next/sandbox#subdirectory=cli"
export SBX_API_KEY=<your key> # from the console
git clone --depth 1 https://github.com/agent-next/sandbox && cd sandbox
python3 cookbook/plc-st/run.pyNo key? Run the judge on any Debian 12 box
# from cookbook/plc-st/
bash judge/setup.sh
bash judge/selftest.sh
bash judge/grade.sh examples/good/tank_ctrl.st --json verdict.jsonResults
Why a sandbox
The agent installs a pinned compiler, compiles its own code and iterates against the judge in an isolated, disposable machine; nothing it does touches your machine.
Measured wall time
| Step | Wall time |
|---|---|
judge/setup.sh (fresh install of pinned MATIEC) | ~39 s |
judge/selftest.sh (good + 6 mutants) | ~33 s |
judge/grade.sh examples/good/tank_ctrl.st | ~5 s |
Limits, plainly
- An educational interlock exercise, not a certified safety system: no SIL rating, no redundant architecture, no formal proof.
- The plant model is analytic and deterministic; faults are scripted stuck or false switch states and E-stop pulses.
Source
Demo folder · SPEC · RECEIPT · REPRODUCE — pinned at ba328e6
Run one yourself
Sign in with GitHub for a free key with 10 sandbox-hours. Every demo above finishes in minutes and kills its sandbox when it is done.

