Lion Cipher Lab

Stop terminal escape sequences in LLM output from hijacking an analyst's terminal (deterministic stub model)

Why it matters

Command-line triage tools are starting to put a language model between the logs and the analyst: the tool reads a few hundred log lines, the model writes a summary, and the tool prints it in the terminal. Part of every log line is written by whoever caused it - a username, a hostname, a request path - and models quote the lines they summarise. A terminal does not just display text: certain characters are instructions to it. They can make text invisible, move the cursor back and draw a calmer line over a 'Failed password for root', put a hyperlink on the screen whose target is not the text you…

What you'll learn

Steps in this lab

  1. The words first: control characters, ESC, CSI, OSC, SGR, C1 - and the fact that the model is a stub
  2. Open a terminal, check Python, make a scratch folder (Windows, macOS, Linux)
  3. Build 300 log lines: honest ones, legitimately coloured ones, and seven kinds of planted canary sequence
  4. Write the STUB summariser and read its whole error model: it never invents a sequence, it only copies one
  5. Build vt.py: a tiny interpreter that reports what a terminal WOULD do, so you never have to let it
  6. Write the four render paths: naive, strip 7-bit ESC, escape everything, and an allowlist that re-applies only your colours
  7. Measure: planted effects reaching the terminal per mode, and the damage each mode does to honest and coloured lines
  8. Read the results: why strip7 half-works, why escape and allowlist both work, and what each one costs
  9. The honest negatives: bidi passes everything, escaping is expensive, stripping rewrites evidence, and 8-bit is a worst case
  10. Why this, not that - and how this lab differs from its neighbours
  11. When NOT to - and how a pro does it differently
  12. One experiment, an optional local model, then clean up

Open the full interactive lab →