AI can now generate thousands of lines of glue code in seconds, but reviewing it, sandboxing it, and keeping long-running workflows from breaking in production is a nightmare. StateScript gives teams and agents one small, verifiable language that enforces permissions, survives crashes cleanly, and cuts codebase size in half.
// Permissions are explicit. Budgets cannot be escalated. use fs, sh policy ci = budget(fuel: 50000, time: 30s), caps(fs: "ro") var approved = false view canShip: bool = approved // Proven BEFORE a single line runs in production: invariant !(inState(deploying) && !canShip) eventually inState(live) || inState(aborted) || inState(timedOut) state review { on approve { approved = true } -> deploying on reject -> aborted after 24h -> timedOut } state deploying { entry { transact { unwind { sh.run("rollback-release") } res = try sh.run("deploy-prod") if res.ok { -> live } else { -> aborted } } } }
You don’t need another syntax for writing for-loops. You need a way to ship reliable automation when AI agents are writing code, touching real systems, waiting hours for humans, and burning through context windows. Here is what breaks with general-purpose glue code, and what StateScript solves out of the box.
Giving an LLM bash or Python means trusting a prompt not to touch production. In StateScript, every file declares
the exact permissions it needs (use fs) and runs under monotonic policy limits inside a
WebAssembly sandbox that can tighten budgets, never widen them.
Long-running workflows crash, deploy mid-flight, or wait 24 hours for a human click. Instead of replaying
code from line 1 and exploding on nondeterminism, StateScript pauses into a tiny, inspectable JSON snapshot
and resumes right where it stopped, with transact + unwind automatic rollback on failure.
Verbose boilerplate slows down human code review and fills AI context windows with noise. Compact pipelines
(|), pattern matching, and first-class states cut real production libraries by more than half
while eliminating entire classes of bugs.
One source file compiles directly to a ~7.9 KB sandboxed .wasm module (with zero C toolchain required)
or to a standalone ~47.1 KB Full-LTO LLVM native binary that outperforms Node/V8 on the majority of real workloads.
Unit tests only check the paths someone remembered to write, while AI-generated code loves hiding bugs in rare retry, timeout, or approval sequences. StateScript automatically checks every reachable state before deployment and exports 1:1 proofs to Lean 4, TLA+, and Z3 so critical rules are proven true, not just hoped true.
approved = true in the Playground to watch the checker catch it.
Reviewing AI-written code shouldn’t mean reverse-engineering tangled callbacks. Every StateScript module
auto-generates clear Mermaid state diagrams, produces RFC-style ASCII packet diagrams from declarative binary
frame and grammar rules, and embeds its exact permission manifest into the binary.
website/server.st · Live Stats).Pick a real scenario to compare typical production glue code against one verifiable StateScript module.
# 1. Agent calls list_files() -> dumps 400 paths into context # 2. Agent calls read_file() 12 times -> 60 KB raw code in context # 3. Runs unsandboxed shell with full env vars & write access # 4. No hard fuel/time cap; runaway loop burns $$$ files = glob.glob("src/**/*.ts", recursive=True) results = [] for f in files: txt = open(f).read() # hope prompt didn't ask for /etc/passwd! lines = txt.count("\n") if lines > 100: results.append({"path": f, "lines": lines, "bytes": len(txt)}) results.sort(key=lambda r: -r["lines"]) print(json.dumps(results[:5]))
use fs policy audit = budget(fuel: 50000, calls: 200, time: 5s), caps(fs: "ro") return under audit { fs.glob("src/**/*.ts") | map(fs.read(.)) | where(.lines > 100) | select("path", "lines", "bytes") | sort(-.lines) | take(5) }
caps(fs: "ro") and fuel: 50000 at the WASM boundary, so even a prompt-injected agent literally cannot write files, leak secrets, or infinite-loop.// Forget one finally/catch branch and inventory stays locked forever
let reserved = false;
try {
await reserveInventory(orderId);
reserved = true;
await chargeCard(orderId);
await sendReceipt(orderId);
} catch (err) {
if (reserved) {
try { await releaseInventory(orderId); } catch {}
}
throw err;
}
transact { reserved += amount unwind { releaseInventory(orderId) } charge = try chargeCard(orderId) if !charge.ok { return err(charge.error) } charged += amount }
unwind executes only when a scope fails or rolls back, keeping cleanup right next to the action it undoes, while transact snapshots and restores durable variables automatically.NodeRedis/node-redis-parser : 370 SLOC (bare CR smuggling bug) websockets/ws frame parser : 522 SLOC (JS Buffer state sprawl) nats-io/nats.js protocol : 704 SLOC (167 cyclomatic complexity) motdotla/dotenv parser : 302 SLOC (prototype & escape quirks) sindresorhus/quick-lru : 258 SLOC (2x hidden memory overhead)
redis-parser.st : 97 SLOC (-74%) · 7.5 KB .wasm · strict CRLF ws-frame.st : 107 SLOC (-80%) · 12.8 KB .wasm · RFC 6455 guard nats-protocol.st : 127 SLOC (-82%) · 7.0 KB .wasm · 31 CC (-81%) dotenv.st : 90 SLOC (-70%) · 5.4 KB .wasm · 2.74× vs V8 quick-lru.st : 98 SLOC (-62%) · 6.6 KB .wasm · exact cap inv
Live data exported directly from corpus/benchmarks.sqlite.
| Library | Category | SLOC Compression | .wasm Size | Native Bin | LLVM vs V8 |
|---|---|---|---|---|---|
| Loading live corpus metrics… | |||||
Requires Node 22+ (zero npm runtime packages). Add Clang/LLVM only if you want standalone native binaries.
git clone https://github.com/visionik/statescript && cd statescript && node src/cli.ts verify examples/11-verified-deploy.st