marsh

Stock-SBX adapter

marsh-sbx is the only boundary to the installed Docker Sandboxes runtime. It runs an absolute, startup-resolved stock sbx binary and uses its public create, ls, inspect, mount, umount, cp, exec, stop, and rm operations. It does not start another SBX service, ship a patched binary, or run a registered command directly in a VM. Host sbx is trusted.

Version and installation

Startup requires stock SBX v0.47.0 or newer: it parses the reported version line (a release, or a nightly whose -N-gABBREV suffix matches the line's 40-hex commit), refuses an older one, and probes the local Kit v3 create surface before creating product state. It pins no version and no commit beyond that minimum. Older inventory fixtures (from v0.46.0, for example) remain as parser and model coverage, not supported releases. The version check does not qualify every later version or prove that a build has the EROFS writable-layer discard fix; acceptance checks container cleanup directly.

Homebrew owns installation of sbx. The client and marshd each resolve MARSH_SBX, otherwise sbx on PATH, and canonicalize it to an absolute path; the daemon refuses a relative one. A running daemon keeps the executable it resolved at startup, and its handshake includes a digest of that executable, so a client restarts an idle daemon after an SBX upgrade. A daemon never switches to another executable. When Homebrew deletes the pinned one, the daemon reports it (marsh status, the busy refusal, a skipped Kit update check), and once nothing is attached, starting, running, or in flight it stops on its own so the next call starts a daemon that passes the startup checks with the new SBX. MCP registrations keep their stored path; rerun them after an upgrade.

Stock resolves an unprefixed Kit reference by first looking for a file or directory of that name in its working directory, so a directory a job writes in a project, named like docker.io/org/kit:tag, could stand in for a registry Kit. marshd therefore enters its private control directory (never mounted into a guest) before its first stock call, whatever directory it was started from. Every Kit or tag reference marsh hands stock (create, --cloud create, kit inspect) carries oci:// (registry_kit_reference); local Kit sources are absolute directories. Stock calls that name no Kit may still run elsewhere: sbx mount and sbx umount in the grant's source (to name the mount relative to it) or /, and the MCP publication and load calls (sbx mcp ..., from the daemon, the host marsh it starts, and the marsh CLI) in the session's launch directory or workspace.

Before it leaves its launch directory, marshd makes its path settings absolute against it (--home, MARSH_HOME, MARSH_GUEST_ARTIFACTS, MARSH_KIT_IMAGE_CACHE, MARSH_OWNERSHIP_MIRROR), and resolves its program settings. A value with a / is a path, made absolute the same way. A bare name is never looked up in the launch directory: MARSH_SBX (also when unset, as sbx) and MARSH_OPEN_COMMAND on the absolute entries of the inherited PATH, skipping empty and relative entries such as ., as the client does for MARSH_SBX; MARSH_DOCKER on the fixed PATH Docker commands run with (/usr/local/bin:/opt/homebrew/bin:/usr/bin:/bin). An upgrade's successor starts in / and is handed these resolved values in place of the ones it would inherit.

Ownership map and names

Every VM marsh creates has a random name: marsh-k- plus 8 base36 characters for Kit VMs, marsh-s- for shell VMs. vm_ownership.rs keeps a persisted map from (purpose, key) to name and observed UUID in the host control directory.

  • A missing entry gets a fresh random name, persisted as an intent before sbx create. After create the UUID is recorded.
  • The next inventory adopts an intent whose name is present and drops one, loaded at startup, whose name is absent.
  • A VM is usable only if its name is present with the recorded UUID. A name with a different UUID, or not in the map, is foreign and refused.
  • Stop and remove target only a recorded UUID that is currently present (remove_owned_vm classifies afresh first). Removal drops the entry, so the next use gets a new name, except that a replacement created under a just-removed name (an unhealthy Kit VM, a shell VM whose image changed) persists that name as an intent again (restore_intent), and record restores a name retired in this process to its old purpose and key.
  • The warm paths that mount, pull an image into, or install a binary in a Kit VM address it by name, on the ReadyKitVm that classification produced when it was made ready; they do not classify again. They rely on the host trust and the name rule above (no other actor creates a VM under a name this daemon chose), not on a UUID check at each call.

Warm requests use a cached sbx ls --json view, refreshed on cold start, after a lifecycle change, or after a failure. docs/model/Ownership.tla specifies this protocol.

Kit VMs and fresh containers

A registry entry names a native Kit v3 source directory or an immutable Kit OCI reference; mutable tags are rejected. The Kit's OCI config and descriptor own entrypoint, command, environment, user, workdir, capabilities, network policy, and services. The adapter does not translate or add to them. Local source is an authoring path; the full acceptance run uses published digests.

Each Kit VM runs one retained sbx exec -i ... marsh-worker --serve transport, which also keeps stock SBX from stopping an idle VM. The worker reports its generation at startup and answers liveness pings. Per attempt the daemon admits the sources, takes a reference on the retained mounts, sends bounded attempt-keyed frames (start, input, EOF, signal, resize, cancel), relays output, and records the terminal report. The worker creates one container from the exact Kit image with the host user's nonroot UID/GID, natural cwd and home, exact grants, and resource ceilings; reports Docker's container ID; waits; deletes the container; and verifies its absence.

Jobs keep the image's static environment plus validated HOME, USER, LOGNAME, and MARSH_SELECTED_HOME. When stock SBX provides them, the adapter also passes only the fixed proxy endpoint, bounded credential-mode sentinels, a read-only CA bundle, and the sandbox-local MCP Gateway URL and sentinel name as a pair. Gateway tools loaded into a Kit VM are visible to every job in it. Jobs receive no proxy-held raw credentials, worker environment, or Docker/SBX socket. Their daemon requests go through the scoped job capability socket (docs/design/processes.md). An agent's explicit login can persist state in the shared guest home; the security model distinguishes that from SBX's proxy-held credentials.

--load prepares the VM, worker, and job image before returning.

Shell VM and relay

The shell VM uses the packaged shell template, built on the DHI Debian ARM64 base. The adapter installs the Linux marsh and relay binaries, creates the Mac user's UID/GID, and mounts the launch directory at its identical path and the selected home backing (MARSH_HOME/home, or an ephemeral slot) at /Users/<user>. The real Mac home is never mounted. Attachment uses sbx exec -it or sbx exec -i. The relay runs as the shell user with a session-scoped socket and token in a 0700 runtime directory; the token never appears in argv, the home, or a job environment.

Mounts

Sources are opened with O_DIRECTORY|O_NOFOLLOW|O_CLOEXEC at admission and their identity (device, inode, owner and group, from fstat; marsh-sbx/src/source_chain.rs) is checked before and after sbx mount. That identity can be recycled by a replacement; the APFS volume UUID and persistent file ID that marsh-host-identity reads are not part of source admission (they identify checkpoint directories, marsh-daemon/src/checkpoint.rs). Natural host paths are only mount targets, never authority. A mount is made on first use and retained while the VM is warm; concurrent users share it by reference. An idle mount is replaced only when its source identity changed, and mounts are released when the VM is retired. Stock SBX accepts only pathname mount sources, so the reopen inside sbx mount is an upstream limitation accepted under the trusted-host assumption.

Failure behavior

Unknown state is never treated as absence or success. The adapter does not create a second daemon or VM pool, replay a job, or fall back to direct VM execution. Memory, PID, output, writable-layer, and wall limits produce typed outcomes. Transport loss during active work, uncertain container cleanup, or a missing create-boundary event within the bounded wait produces a nonzero cleanup_uncertain receipt and quarantines the VM. A quarantined Kit VM takes no new jobs until marsh workers reset KIT retires it; the next use creates a fresh VM under a new random name. marsh reset and marsh stop clean up the whole scope once no shells or jobs are active. Do not delete the journal or ownership map as a recovery shortcut.

Edit this page on GitHub