Runtime configuration
Schema and operational reference for lema.runtime-linux/v2, lema.cap-config/v1, and lema.secret-bundle/v1.
Running a Lema store or executing a VM application uses three configuration schemas:
lema.runtime-linux/v2(runtime.json): Selects the host sandbox profile and the paths for the pinned Lean distribution, execution ledger and native-call lock. The same schema applies on Linux and macOS.lema.cap-config/v1(lema-cap.json): Grants concrete TCP origins/listeners, UDP endpoints, 4 KiB block devices, handle limits, and secret roles toCapHost(crates/lema-cap).lema.secret-bundle/v1(secret-<version>.bundle): Packages versioned credentials and mandatory TLS trust anchors forSecretPolicy,exchange, andserve.
Host runtime configuration (lema.runtime-linux/v2)
Lema supports two modes of lema.runtime-linux/v2:
- Checking runtime (elaboration and kernel replay): Includes the
"distribution"path pointing to the host’s pinned Lean4.34.1toolchain so the server can elaborate.lema/.leansource and replay canonical objects. - VM-only deployment runtime (
docs/deploy.md): Omits"distribution"entirely. A production VM host running pre-builtlema.vm-app/v1releases needs neither the Lean distribution nor a Rust compiler installed on the machine.
For Apple Silicon macOS, a checking configuration looks like this:
{
"schema": "lema.runtime-linux/v2",
"distribution": "/Users/alice/.lema/toolchains/lean-4.34.1-darwin-aarch64",
"output": "/Users/alice/.lema/evidence",
"shared_lock": "/Users/alice/.lema/native.lock",
"profile": "macos"
}On Linux x86_64, use the Linux distribution directory and "profile": "systemd-scope" or "profile": "container". lema setup selects a host profile when creating a configuration and preserves existing configurations.
Top-level fields of lema.runtime-linux/v2
| Field | Type | Required | Description |
|---|---|---|---|
schema | "lema.runtime-linux/v2" | Yes | Runtime configuration schema identifier. |
profile | "systemd-scope" | "container" | "macos" | Required on macOS; optional on Linux | Defaults to systemd-scope. Linux accepts systemd-scope (bubblewrap in a systemd user scope) or container (bubblewrap with cgroup v1 or rlimit supervision). Apple Silicon macOS requires macos (Seatbelt and a process-group watchdog). A profile for the other host is refused. |
distribution | Path string | Checking only | Absolute path to the verified Lean 4.34.1 distribution directory. Omit on VM-only deployment hosts. |
output | Path string | Yes | Directory for the execution ledger, per-call logs, module cache, and HALTED latch. |
shared_lock | Path string | Yes | Machine-wide lock path coordinating native calls and hosting the <shared_lock>.HALTED latch. All configurations on one host should share it. |
These are the accepted v2 fields. pins, call_budget and other unknown fields are refused. Toolchain pins and resource limits come from the build and the call, not operator JSON. The runtime records host file digests when loaded and checks that those files stay unchanged before each call; a difference from a historical reviewed host pin is reported by lema pins-report, without itself refusing the host.
The macOS profile uses kernel CPU/process limits and sampled physical-memory/thread limits. Sampled bounds may briefly overshoot, swap and a hard thread cap are not enforced, and daemons retain their deadline. Worker binaries, module caches and releases are local to their target; the Linux profile cannot be used to check a Darwin release or vice versa.
Output directory layout, ledger, and HALTED latches
Inside the configured output directory, the runtime maintains an auditable trail of every sandboxed call:
| Path | Description |
|---|---|
ledger.jsonl | Append-only JSON Lines log recording three lifecycle events per call: reserve (before spawn), complete (exit status and resource usage), and resolved (post-call cleanup confirmed). |
<CALL>-reserved.json | Reservation ticket written and fsynced before the sandbox process starts. |
<CALL>.log | Captured standard output and standard error from the sandboxed process. |
<CALL>-result.json | Final structured result, exit code, wall-clock duration, and peak memory usage. |
work/<CALL>/ | Scratch directory exposed to the sandbox. Keep failure evidence when investigating a call. |
modules/ | Content-addressed .olean cache for elaborated store objects. |
artifacts/ and vm-workers/ | Compiled lema.vm-app/v1 bundles and worker descriptors (vm-workers/<sha256>.json). |
HALTED | Fail-closed latch file written if a sandbox process fails to terminate, leaves an uncleaned reservation, or violates a pin check. |
Pre-call checks and fail-closed HALTED recovery
Before spawning a sandboxed call, the runtime checks its configuration, host files, previous call records and resource reserves:
- Neither
<output>/HALTEDnor<shared_lock>.HALTEDexists. - Host binaries and libraries still match the digests recorded when the runtime loaded, and the configuration and distribution have not changed.
- Every prior
reserveentry inledger.jsonlhas a matchingresolvedentry (an orphaned reservation immediately writesHALTED). - The filesystems holding
outputandshared_lockretain at least4 GiBfree, plus reserves for calls in flight. The Linuxsystemd-scopeprofile also requires6 GiBof available memory plus call headroom. Container and macOS profiles record memory availability without that admission floor; Linux PSI pressure is recorded rather than used as a refusal threshold.
On macOS, failed resource accounting or a lost watchdog ends the call. Incomplete process-group cleanup retains the group record and halts later calls.
See Recover from HALTED for step-by-step instructions on inspecting ledger.jsonl and clearing a latch.
Capability configuration (lema.cap-config/v1)
When lema run or lema-vm-runner starts an application, it reads a lema.cap-config/v1 JSON file (typically lema-cap.json) to configure CapHost (crates/lema-cap).
A program can only address network peers, listeners, block devices, or secret roles that appear in this table by their 0-based u16 index. Legacy v0.1 fields (origins and files.state_dir) are refused at parse time.
{
"block_devices": [
{
"path": "/var/lib/lema/s3d-data.blk"
}
],
"max_open_handles": 64,
"schema": "lema.cap-config/v1",
"secrets": {
"dir": "/var/lib/lema/secrets",
"grants": [
{
"name": "s3-inbound-auth",
"role": "sigv4_verify_server"
}
]
},
"tcp_listeners": [
{
"address": "127.0.0.1:8443",
"max_deadline_ms": 5000,
"max_recv_bytes": 65536
}
],
"tcp_origins": [
{
"address": "127.0.0.1:9000",
"max_deadline_ms": 5000,
"max_recv_bytes": 65536
}
],
"udp_endpoints": []
}lema.cap-config/v1 fields
| Field | Type | Default / Bounds | Description |
|---|---|---|---|
schema | "lema.cap-config/v1" | Required | Capability configuration schema identifier. |
max_open_handles | Integer (u16) | Default 64, max 256 | Maximum simultaneous open handles across all capability families (tcp, udp, block, secret). |
tcp_origins | Array of objects | Optional | Outbound TCP targets (address, max_recv_bytes <= 65536, max_deadline_ms <= 60000), addressed by origin_idx. |
tcp_listeners | Array of objects | Optional | Inbound TCP bind addresses (address, max_recv_bytes <= 65536, max_deadline_ms <= 60000), addressed by listener_idx. Also used by serve. |
udp_endpoints | Array of objects | Optional | Connected UDP peers (bind_address, peer_address, max_recv_bytes <= 65536, max_deadline_ms <= 60000), addressed by endpoint_idx. |
block_devices | Array of objects | Optional | Backing files or block devices (path), addressed by device_idx. Each file size must be a non-zero multiple of 4096 bytes (1..=1,048,576 blocks) and is locked exclusively via File::try_lock(). |
secrets | Object ({dir, grants}) | Optional | Directory containing secret-<version>.bundle files and the ordered grants array (name, role) addressed by grant_idx. |
Secret bundles (lema.secret-bundle/v1)
Secrets are never embedded in lema-cap.json or passed as command-line arguments. Instead, operators package raw secret files and TLS trust anchors into a versioned secret-<version>.bundle file inside secrets.dir using lema secret bundle --spec spec.json --out <DIR>.
Secret bundle specification (lema.secret-bundle/v1)
{
"entries": [
{
"name": "upstream-s3",
"role": "sigv4",
"secret_file": "/run/secrets/aws_secret_key",
"tls": {
"anchors": [
{
"key": "3059301306072a8648ce3d020106082a8648ce3d03010703420004...",
"kind": "p256",
"subject": "CN=s3.example.internal"
}
],
"server_name": "s3.example.internal"
}
},
{
"name": "s3-inbound-auth",
"role": "sigv4_verify_server",
"secret_file": "/run/secrets/inbound_sigv4_key"
}
],
"schema": "lema.secret-bundle/v1",
"version": 1
}Secret roles and mandatory TLS binding
| Role string | Secret size / format | tls block required? | Purpose |
|---|---|---|---|
"sigv4" | Secret access key bytes (<= 4096 B) | Yes (server_name + anchors) | Outbound AWS SigV4 request signing via SecretPolicy and exchange. |
"bearer_header" | Bearer token bytes (<= 4096 B) | Yes (server_name + anchors) | Outbound Authorization: Bearer header injection via exchange. |
"sigv4_verify_server" | Shared verification key (<= 4096 B) | Optional (uses server cert/key for serve) | Inbound SigV4 request verification via SecretPolicy and serve. |
"x25519_static" | Exact 32 bytes | No | Static X25519 secret scalar for Noise_XX or X25519.dh. |
"ed25519_sign" | Exact 32 bytes | No | Ed25519 secret seed for Ed25519.sign and TLS 1.3 CertificateVerify. |
Each entry in tls.anchors pins a trusted root or leaf public key by subject (distinguished name bytes), kind ("ed25519", "p256", or "rsa"), and key (SPKI public key bytes). lema secret bundle writes <out>/secret-<version>.bundle with an integrity SHA-256 footer; at runtime, CapHost atomically loads the highest-numbered valid secret-<version>.bundle in secrets.dir so credentials can be rotated without restarting the host.
Lema v0.3.2 · Updated 29 October 2026 · Version and compatibility