Skip to content

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:

  1. 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.
  2. lema.cap-config/v1 (lema-cap.json): Grants concrete TCP origins/listeners, UDP endpoints, 4 KiB block devices, handle limits, and secret roles to CapHost (crates/lema-cap).
  3. lema.secret-bundle/v1 (secret-<version>.bundle): Packages versioned credentials and mandatory TLS trust anchors for SecretPolicy, exchange, and serve.

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 Lean 4.34.1 toolchain so the server can elaborate .lema/.lean source and replay canonical objects.
  • VM-only deployment runtime (docs/deploy.md): Omits "distribution" entirely. A production VM host running pre-built lema.vm-app/v1 releases needs neither the Lean distribution nor a Rust compiler installed on the machine.

For Apple Silicon macOS, a checking configuration looks like this:

/Users/alice/.lema/runtime.json
{
  "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

FieldTypeRequiredDescription
schema"lema.runtime-linux/v2"YesRuntime configuration schema identifier.
profile"systemd-scope" | "container" | "macos"Required on macOS; optional on LinuxDefaults 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.
distributionPath stringChecking onlyAbsolute path to the verified Lean 4.34.1 distribution directory. Omit on VM-only deployment hosts.
outputPath stringYesDirectory for the execution ledger, per-call logs, module cache, and HALTED latch.
shared_lockPath stringYesMachine-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:

PathDescription
ledger.jsonlAppend-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.jsonReservation ticket written and fsynced before the sandbox process starts.
<CALL>.logCaptured standard output and standard error from the sandboxed process.
<CALL>-result.jsonFinal 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).
HALTEDFail-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:

  1. Neither <output>/HALTED nor <shared_lock>.HALTED exists.
  2. Host binaries and libraries still match the digests recorded when the runtime loaded, and the configuration and distribution have not changed.
  3. Every prior reserve entry in ledger.jsonl has a matching resolved entry (an orphaned reservation immediately writes HALTED).
  4. The filesystems holding output and shared_lock retain at least 4 GiB free, plus reserves for calls in flight. The Linux systemd-scope profile also requires 6 GiB of 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.

JSON
{
  "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

FieldTypeDefault / BoundsDescription
schema"lema.cap-config/v1"RequiredCapability configuration schema identifier.
max_open_handlesInteger (u16)Default 64, max 256Maximum simultaneous open handles across all capability families (tcp, udp, block, secret).
tcp_originsArray of objectsOptionalOutbound TCP targets (address, max_recv_bytes <= 65536, max_deadline_ms <= 60000), addressed by origin_idx.
tcp_listenersArray of objectsOptionalInbound TCP bind addresses (address, max_recv_bytes <= 65536, max_deadline_ms <= 60000), addressed by listener_idx. Also used by serve.
udp_endpointsArray of objectsOptionalConnected UDP peers (bind_address, peer_address, max_recv_bytes <= 65536, max_deadline_ms <= 60000), addressed by endpoint_idx.
block_devicesArray of objectsOptionalBacking 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().
secretsObject ({dir, grants})OptionalDirectory 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)

JSON
{
  "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 stringSecret size / formattls 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 bytesNoStatic X25519 secret scalar for Noise_XX or X25519.dh.
"ed25519_sign"Exact 32 bytesNoEd25519 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