Run and release a program on the Lema VM
Run pure ByteArray tests with lema test, execute interactive Prog applications on the Lema VM with automatic family inference and vm-code-cache reuse, watch files with lema dev, and cut a release with lema release and lema run --release.
In Lessons 3 through 5, you authored Pythonic .lema contracts and .lean implementations, checked proofs in the pinned Lean 4.34.1 kernel, and tracked semantic revisions with lema diff and lema commit. Now you will see how Lema compiles accepted store objects to LemaIR and executes them on the Lema VM (lema-vm and lema-vm-runner).
Along the way, you will use all four parts of Lema’s execution workflow:
lema testfor pureByteArraytest roots andProgtest vectors.lema runfor interactiveProgapplications, with automatic command-family inference intolema.exec/v2and<store>/vm-code-cachecompilation reuse.lema devfor continuous file watching acrosssrc/.lema releaseandlema run --releasefor pinning a release artifact and deployment configuration (and why applications that touch secrets must run through a release).
1. Run a pure ByteArray test (lema test)
The simplest runnable unit in Lema is a pure definition of type ByteArray. Because a ByteArray value makes no network or storage calls, lema test evaluates its accepted closure directly in the Lema VM (crates/lema-cli/src/vm_test.rs) and compares the resulting bytes against an explicit test oracle. Use --expect for expected UTF-8 text, --expect-sha256 for its digest, or --report lines for a test-report root.
In your hello project, add a test root Reuse.report to src/Reuse.lean that checks keep and addZero on sample inputs and formats a summary line:
def report : ByteArray :=
if keep (keep 7) == 7 && addZero (addZero 7) == 7 then
"reuse vectors ok\n".toUTF8
else
"reuse vectors fail\n".toUTF8Publish the update and run lema test:
lema add src/Reuse.lean
lema test Reuse.report --expect "reuse vectors ok"test Reuse.report: passed (output matched "reuse vectors ok")Notice that lema test did not invoke lean or a C compiler (leanc was retired in Decision 0052). Instead, Lema read the accepted canonical objects for Reuse.report, Reuse.keep, and Reuse.addZero directly from .lema/store, compiled them in pure Rust to LemaIR (lema.ir/v1), and executed the register bytecode on the Lema VM.
2. Run a Prog application on the Lema VM (lema run)
While pure functions return a ByteArray, real applications interact with timers, storage, network sockets, or concurrent tasks by returning a program value (Prog Cmd Reply A from Core). A Prog value is a pure decision tree: at each step, it either returns a final answer (Prog.ret bytes) or yields a typed command (Prog.call cmd next) and waits for the host runner (lema-vm-runner) to supply the reply.
Inspect src/Main.lean and update it so Hello.app is a Prog application entry point (Nat → ByteArray → Prog AppCmd AppReply ByteArray, where task 0 is the main task and input holds the request bytes passed to the run):
set_option autoImplicit false
namespace Lema
namespace Hello
def app (task : Nat) (input : ByteArray) :
Received.Prog Received.AppCmd Received.AppReply ByteArray :=
Received.ret ("hello, ".toUTF8 ++ input)
end Hello
end LemaPublish src/Main.lean and run Hello.app on the Lema VM with lema run:
echo "world" > input.txt
lema add src/Main.lean
lema run Hello.app --input input.txthello, worldWhat lema run just did automatically
Behind that one-line command, lema run handled three steps that used to require manual JSON manifests:
- Automatic
Progcommand-family inference (LEMA-377):lema runinspected the accepted type ofHello.appin.lema/store, inferred its command families automatically (or used--familiesif you passed an explicit list), and synthesized the store’slema.exec/v2execution record (crates/lema-cli/src/exec_records.rs). - Store-native
LemaIRcompilation and<store>/vm-code-cachereuse (LEMA-352): Lema compiled the accepted closure ofHello.apptoLemaIRand stored the verified compile memo inside.lema/store/vm-code-cache. On subsequent runs, if the accepted root IDs, compiler version, and target (vm) have not changed,lema runreuses the cachedLemaIRartifact immediately without recompiling. - Sandboxed VM execution:
lema-vm-runnerexecuted task0ofHello.appinside the sandbox with deterministic step, allocation, bigint-bit, and call-depth budgets, and printed the returned bytes to standard output.
3. Watch your project continuously with lema dev
When you are actively editing .lema contracts and .lean implementations (or pairing live with an AI coding agent in your editor), run lema dev:
lema devwatching src/ in /home/you/projects/hello (ctrl-c to stop)
[14:02:11] src/Double.lema changed -> re-added src/Double.lema, src/DoubleProof.lean (2/2 contracts checked)Whenever a file under src/ is saved, lema dev automatically:
- parses and elaborates the changed
.lemaor.leanfile; - topologically re-adds any downstream project modules in
lema.jsonwhose symbolic imports (lema.authoring/v2) moved; - prints exact
file:line:colcaret diagnostics if a proof or type check fails; and - updates your contract selection summary (
openvs.checked) in real time.
Press Ctrl-C to stop lema dev when you are ready to cut a release.
4. Cut a release and run through the release gate (lema release and lema run --release)
During development, lema run can directly execute pure tests and applications that do not touch secrets. However, Lema enforces a strict security boundary (mandatory secret admission, LEMA-384 / LEMA-421) whenever an application uses credentials or cryptographic keys:
- Any application that names
Io::Secretor uses the opaqueexchange(clientSigV4/BearerHeader) orserve(serveVerifiedTLS 1.3 +SigV4server) families must pass two staticLemaIRanalyzers at build time:ConstantTime(no secret branches, secret memory indices, or variable-time operations) andSecretFlow.<role>(secrets flow only into approved pinned exchange or server sinks). - In addition, secret-using applications refuse unverified
lema runand can only be executed through an approved release record (lema.release/v1) vialema run --release.
Even for an application without secrets like Hello.app, cutting a release binds the accepted store closure, the compiled LemaIR artifact, the lema-vm-runner worker binary hash, and the deployment configuration (lema-cap.json) into a single immutable record:
lema release Hello.app
lema run --release --input input.txtcreated release #91c4e820a7b3 for Hello.app (target: vm, saved to .lema/last-release)
hello, worldNotice that you did not have to copy and paste the 64-character release ID into lema run --release:
lema releasewrote the newly created release ID (#91c4e820a7b3...) to.lema/last-release.- When you run
lema run --releasewithout an explicit ID inside a project, it reads.lema/last-releaseand runs the full release verification gate: checking every kernel receipt in the closure, the cachedLemaIRcode correspondence, any requiredConstantTimeandSecretFlowguarantee receipts, thelema-vm-runnerbinary digest, and the deployment configuration before starting the VM worker.
Where to go next
You have completed all six tutorials: reading Pythonic .lema and Lean contracts, setting up the toolchain and background server, creating a project, proving a selected contract with Store::check_witness, reusing a general theorem across implementations, and running and releasing code on the Lema VM.
The last lesson, Work alongside an agent in store workspaces, shows how a coding agent and you can work on one project at once, each in a workspace of your own, and bring the agent’s work into main.
From here:
- Explore the How-to guides for step-by-step recipes on working with a project, reviewing and merging semantic changes, replacing an implementation with a proof, configuring capabilities (
lema-cap.jsonand secret bundles), and deploying released VM applications. - Read Explanation for the architecture behind types and contracts, the 6-tag capability boundary, the LemaIR compiler and VM, and the proved HTTPS stack.
- Look up exact schemas, CLI flags, and RPC payloads in the Reference.
Lema v0.3.2 · Updated 29 October 2026 · Version and compatibility