0117: Workspace capability and backends
Status: Proposed — design default, pending the maintainer's confirmation
Context
Agents need isolated working trees with explicit costs and cleanup, without silently copying a repository or escaping its workspace root.
Decision
Add the agent-platform Workspace capability with
the workspace ceiling; existing E0945/E0946 ceiling
diagnostics apply. Expose
ws.fork(label) -> Result[Workspace, WsError],
ws.path() -> Path, ws.fs() -> Fs
attenuated to the workspace root, and
ws.backend() -> str. The structured task owns
workspaces; finish or cancellation releases them, while explicit
detach transfers ownership to the parent. Agent tool processes use
the M10.4 sandbox with their Fs root set to the workspace.
workspace_backend = "auto" probes reflink on the
target filesystem, otherwise selects git-worktree for a git
source, otherwise returns WsError.Unsupported. Git
worktrees are created detached at HEAD without a shell, then dirty
source files are copied in. Reflink clones files with FICLONE.
Overlay is detect-only in v0: report kernel/privilege detection
without mounting, then fall back; actual namespace/mount viability
remains unverified. Full copy is opt-in, never a silent fallback.
Journal the selected backend. An unknown policy value is
E0841.
Place workspaces under
<root>/.harness/ws/<runtime-id>/<agent-id>/
with a runtime lock; startup sweeps stale dead-pid locks. Cleanup
refuses paths outside the workspace root and never follows
symlinks outside it.
Consequences
Unsupported filesystems fail explicitly rather than hiding an expensive copy. Cleanup and sandbox boundaries require security review and tests; overlay is not yet a usable backend.
Alternatives
Always copying is portable but expensive. Selecting overlay on detection alone would promise a backend not implemented in v0.
M13.2 step 12b addendum — Proposed, pending maintainer
OWNER FLAG: the trusted workspace native set is
Workspace.create(path) -> result<Ws, WsError>,
Ws.write(path, bytes) -> result<unit, WsError>,
Ws.read(path) -> result<bytes, WsError>,
Ws.path() -> path, and
Ws.release() -> result<unit, WsError>,
implemented by embedded hrt_ws{,_api,_bridge}.h;
approval is pending maintainer. WsError is a seeded
value union (Io, Denied,
Unsupported, Git,
NoMemory), not a trap. The workspace ceiling controls
creation, and unforgeable Ws handles carry subsequent
authority.
Conservative interim ownership is the whole invocation: the C runner uses exit cleanup (also on language traps/exit); the interpreter runner drops handles on every outcome. Explicit release is idempotent and invalidates aliases. Cleanup failure preserves stale-lock evidence; SIGKILL requires a later sweep. Per-agent finish/cancel/detach release and runtime/agent directory nesting remain open, not implemented promises.
The interpreter synchronously invokes the same C implementation through private opaque tokens, validating directory identity on each reopen. No daemon, Rust unsafe code, new crate, shell Git invocation or alternative path-policy implementation is added. Source/config and administrative-root trust assumptions remain unchanged. Alternatives: a Rust filesystem implementation would duplicate security-sensitive confinement logic; persistent helper processes would complicate cancellation and lifecycle ownership. Neither is chosen for this step. The bridge requires an available C compiler and incurs per-call process overhead. Scoped Fs access and journaled backend choice remain deferred under this Proposed ADR.
M13.2 steps 13–15 implementation details
Reflink probing creates two exclusive temporary regular files
in the source's descriptor-opened .harness/ws, writes
data, attempts FICLONE and removes both files. The native probe
returns passed/unavailable with a reason; unsupported platforms
never emulate reflink with a full copy. Tree snapshots exclude
.git and .harness at every level and
reject symlinks, multiply-linked regular files and special files;
recursive descent is capped at 128 directories. Files retain
permission bits, not ownership, timestamps or extended attributes.
Cleanup shares the existing confined deletion and PID-lock sweep.
Metadata exclusion avoids recursive cloning of workspaces and Git
administrative authority; copying Git metadata or following
internal symlinks are rejected alternatives.
Platform [policy].workspace_backend defaults to
"auto"; the only explicit selections are
"reflink", "git-worktree", and
"copy". Other strings and non-string values produce
E0841. C emission and the synchronous interpreter bridge both
carry the validated selection, never an environment override. Auto
probes reflink first, then checks for a Git source; it never
selects copy and never retries with copy after an individual file
fails to clone. Explicit copy uses the same confined snapshot
traversal with ordinary read/write instead of FICLONE. Git sources
must still be worktree roots, matching the existing backend's
authority boundary.
Overlay's native probe is deliberately detection-only: it reads
Linux kernel filesystem advertisements and checks effective
root/CAP_SYS_ADMIN privilege. Unprivileged callers, missing procfs
and other platforms report unavailable with a reason. A passed
detection means advertised support with privilege,
not verified mount or namespace viability; the
reason states this limitation and the reflink → git-worktree →
Unsupported fallback. No namespace, mount, privilege change or
subprocess is attempted. Overlay is never selected, even when
detection passes; workspace_backend = "overlay"
remains E0841. Alternatives: an actual probe mount would violate
the no-mount requirement for this step and risks namespace leaks;
reporting an unprivileged filesystem advertisement as usable would
overstate support. Full overlay and mount-viability verification
remain deferred.
The native probe API is
hrt_ws_probe_reflink(source) and
hrt_ws_probe_overlay(), returning
{passed, reason}; no additional source-language
methods are introduced. Workspace read/write reject absolute,
traversal and reserved paths and require existing parents.
Released aliases have empty paths and return Denied
on read/write. Git config and the administrative root remain
trusted; these workspaces are not process sandboxes. This detail
lives here rather than exceeding the agent DOCS token budget.
M13.2 step 16 — workspace tool processes
Trusted ToolPort.call_tool adapters use
tools.workspace_tool_process with their owner's
Ws, not a path supplied by tool arguments. It rejects
empty/released paths, restricts Fs to that path and delegates to
the existing grant/network checks and
Process.sandbox.
WorkspaceFs.restrict_workspace(root) is trusted host
glue implementing host.fs.restrict(root): Fs
attenuation currently needs the host package's fs ceiling, unlike
Net attenuation. No new native or ambient workspace selection is
added. The native path accessor also rejects replaced directory
identities, matching the interpreter bridge.
Both Process.run and run_input
enforce the selected root through M10.4, including binary stdin
for run_input. Only that workspace is writable; the
existing fixed system read/execute roots, network restrictions,
parent read-only restrictions, environment and fail-closed errors
remain unchanged. This selects filesystem authority, not cwd;
relative tool paths must be resolved by the adapter. Linux
enforcement is tested; macOS remains unverified.
Alternatives: choosing the latest workspace globally would grant sibling authority; inferring one from agent record fields would invent an implicit ownership convention. Both are rejected. Extending the compiler's Fs ceiling exemption would touch the out-of-scope type checker; the explicit trusted host hook preserves today's ceiling instead. The runner still has no per-owner workspace table: binding the correct handle in a tool port remains trusted host responsibility, as invocation-level ownership already does. Previously acquired process handles are not revocable; release must follow synchronous tool completion. Administrative-root mutation races remain under the existing trusted-root assumption.
Regression coverage dispatches through run →
CallTool, exercises capture with and without stdin on
both backends, permits workspace writes and denies source,
sibling, absolute outside, traversal and symlink writes. Native
identity replacement and sandbox tests also run under ASan/UBSan.
Unavailable sandboxes deny spawning, never fall back.
M17.13 completion addendum
The owner explicitly authorized the per-agent prerequisite and vc integration on 2026-11-05. ADR-0169 supersedes the invocation-only ownership limitation and nested-directory proposal for the implemented structured runner. Legacy invocation cleanup remains a fallback. The vc backend, private command authority, retained recovery state, explicit task ownership and finish/cancel/detach behavior are defined there.