0284. Platform capability ergonomics and multi-root sandboxes
- Status: Accepted (maintainer, 2026-11-25; frozen-file edits listed here approved)
- Date: 2026-11-25
- Plan: M25.3 (Agent velocity Wave 1, T04); amends 0050, 0054, 0087, 0095, 0096, 0097
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:
Processcannot set a child working directory (cwd) or control environment variables (clear_env/env), forcing/bin/sh+env(1)wrappers.Clihas noClockcapability even thoughagentplatform already exposesClock.now_ms(), andagentplatform'sHostdoes not exposeargs/raw_args, forcingCODING_HARNESS_ARGSenv hacks.Fshas nostat/lstat/mkdir/ pruned walk (walk_pruned), forcing externalfind(1)FIFO checks and full subtree walks before filtering.Stdin/Filereaders lack bounded partial reads (read_some) and capped line streaming (byte_lines_max), forcing byte-at-a-timechunks(1)loops to prevent unbounded RSS growth on newline-free input.Process.sandbox(fs, net)grants only one filesystem root, preventing sandboxedgitinside linked worktrees whose.gitfile points at an externalgitdir/commondirwithout widening to an ancestor directory.
Decision
Add five cohesive, capability-preserving platform extensions across both C and interpreter backends:
- Process configuration (
Process):Process.cwd(p: path) -> Process: sets child working directory for subsequentrun/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 minimalPATHonly 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 (returningCliError.Failedat spawn).
- Clock on
cli& argv onagent:- Expose
Cli.clock: Clock(Clock.now_ms() -> i64) onplugins/cli, reusing the existingClock.now_msnative. - Expose
Host.args: vec<str>andHost.raw_args: vec<bytes>onplugins/agent, reusing the existingargs/raw_argsnatives.
- Expose
- Filesystem metadata, directory creation, and pruned
walk (
Fs):- Add seeded
struct FileStat { kind: str, size: i64, mtime_ms: i64 }wherekindis"file","dir","symlink", or"other"(FIFOs, sockets, devices). Fs.stat(p: path) -> result<FileStat, CliError>andFs.lstat(p: path) -> result<FileStat, CliError>(honoringFsroot confinement andno_follow;lstatnever opens or blocks on FIFOs).Fs.mkdir(p: path) -> result<unit, CliError>(creates a single directory inside the writableFsroot with mode0700; refusesread_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).
- Add seeded
- 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; emptybyteson EOF;max_bytes < 1traps matchingchunks).byte_lines_max(max_bytes: i64) -> result<vec<bytes>, CliError>/ streamingforhead: caps each buffered line atmax_bytesbytes (trapping or returningCliError.Failed("line exceeds limit")without unbounded allocation;max_bytes < 1traps).
- Multi-root read-only sandbox
(
Process):Process.sandbox_roots(primary: Fs, extra_ro: vec<Fs>, net: Net) -> Process: grants the primaryFs(respecting its read/write mode) plus zero or more additional canonical read-onlyFsroots (attenuated to read-only even if the caller passed a writableFs).- 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)
plugins/cli/platform.toml,plugins/cli/DOCS.md,plugins/cli/native/trt_{cli,io,proc}.hplugins/agent/platform.toml,plugins/agent/DOCS.mdcrates/tenon/src/{platform.rs,platform_decl.rs,lower_platform.rs,cgen.rs,interp.rs,interp_fs.rs,interp_process.rs,sandbox_launcher.rs}docs/spec/LANGUAGE.md(kept within the 6,250-token budget) anddocs/spec/diagnostics.md
Consequences
tenon-dev-mcpcan delete its/bin/shcapture wrappers,find(1)FIFO probes, byte-by-bytestdin.chunks(1)loop, and ancestor-widening linked-worktree workaround.coding-harness-2can replace itsCODING_HARNESS_ARGSwhitespace-only hack with nativeHost.args.- Capability monotonicity is preserved:
clear_env,cwd,read_onlyextra roots, andFsconfinement never widen authority beyond capabilities already held by the caller.