On this page

0284. Platform capability ergonomics and multi-root sandboxes

Context

Real Tenon applications (tenon-dev-mcp, coding-harness-2) hit seven reproduced platform omissions documented in tenon-dev-mcp/docs/GAPS.md (G2, G3, G4, G5, G6, G15, G18) and coding-harness-2/README.md:

  1. Process cannot set a child working directory (cwd) or control environment variables (clear_env / env), forcing /bin/sh + env(1) wrappers.
  2. Cli has no Clock capability even though agent platform already exposes Clock.now_ms(), and agent platform's Host does not expose args / raw_args, forcing CODING_HARNESS_ARGS env hacks.
  3. Fs has no stat / lstat / mkdir / pruned walk (walk_pruned), forcing external find(1) FIFO checks and full subtree walks before filtering.
  4. Stdin / File readers lack bounded partial reads (read_some) and capped line streaming (byte_lines_max), forcing byte-at-a-time chunks(1) loops to prevent unbounded RSS growth on newline-free input.
  5. Process.sandbox(fs, net) grants only one filesystem root, preventing sandboxed git inside linked worktrees whose .git file points at an external gitdir/commondir without widening to an ancestor directory.

Decision

Add five cohesive, capability-preserving platform extensions across both C and interpreter backends:

  1. Process configuration (Process):
    • Process.cwd(p: path) -> Process: sets child working directory for subsequent run / run_input / stream. When sandboxed, the cwd must resolve inside the sandbox filesystem root (or fail closed).
    • Process.clear_env() -> Process: clears inherited environment variables before applying explicit entries (retaining safe minimal PATH only when sandbox policy requires it).
    • Process.env(key: str, val: str) -> Process: sets one child environment entry; rejects empty keys or keys containing = or NUL (returning CliError.Failed at spawn).
  2. Clock on cli & argv on agent:
    • Expose Cli.clock: Clock (Clock.now_ms() -> i64) on plugins/cli, reusing the existing Clock.now_ms native.
    • Expose Host.args: vec<str> and Host.raw_args: vec<bytes> on plugins/agent, reusing the existing args/raw_args natives.
  3. Filesystem metadata, directory creation, and pruned walk (Fs):
    • Add seeded struct FileStat { kind: str, size: i64, mtime_ms: i64 } where kind is "file", "dir", "symlink", or "other" (FIFOs, sockets, devices).
    • Fs.stat(p: path) -> result<FileStat, CliError> and Fs.lstat(p: path) -> result<FileStat, CliError> (honoring Fs root confinement and no_follow; lstat never opens or blocks on FIFOs).
    • Fs.mkdir(p: path) -> result<unit, CliError> (creates a single directory inside the writable Fs root with mode 0700; refuses read_only() handles and escaping paths).
    • Fs.walk_pruned(p: path, skip_names: vec<str>) -> result<vec<path>, CliError> (skips matching directory basenames before descending, never follows symlinks, skips non-regular files cleanly).
  4. Bounded streaming reads (Stdin, File):
    • read_some(max_bytes: i64) -> result<bytes, CliError>: performs a single bounded read (returning immediately when any bytes are available; empty bytes on EOF; max_bytes < 1 traps matching chunks).
    • byte_lines_max(max_bytes: i64) -> result<vec<bytes>, CliError> / streaming for head: caps each buffered line at max_bytes bytes (trapping or returning CliError.Failed("line exceeds limit") without unbounded allocation; max_bytes < 1 traps).
  5. Multi-root read-only sandbox (Process):
    • Process.sandbox_roots(primary: Fs, extra_ro: vec<Fs>, net: Net) -> Process: grants the primary Fs (respecting its read/write mode) plus zero or more additional canonical read-only Fs roots (attenuated to read-only even if the caller passed a writable Fs).
    • On macOS Seatbelt and Linux Landlock, each extra root grants read-only traversal/reads only inside that exact canonical subtree; failure to apply policy fails closed.

Frozen files approved for M25.3 (T04)

Consequences