Skip to content

backends: the worker sandbox leaves no persistent writable place for scratch, workspaces or file outputs #1626

Closed

Description

@schlessera

Context

0.41.0 ordinary hosted workers expose a read-only brain and no persistent writable utility area. workerCommand mounts the brain read-only at packages/ui-sdk/src/server/worker-launcher.ts:135, creates per-turn scratch at :137 and mounts the host read-only at :132. Reported failures include .brain/scratch writes/prune, workspace clone/fetch, binary outputs and Chromium HOME/XDG caches. Redirecting caches to /tmp allowed a reported render, while persistent scratch still refused. These are reported Docker observations, not a fresh render receipt from triage.

Scope

Deliver the D1–D6 named writable utility areas, hardlink/alias guard, HOME overlay/XDG fallback, clear scratch-command errors and generated capability-note mechanism specified below. This is the strict-profile utility baseline and an input to #1649's later governed profile. It does not implement promotion, pinning or expired-link UI.

Out of scope

Decision (maintainer, 2026-10-11): designed writable areas in the worker

The read-only brain stays for interactive and voice turns, with designed writable areas beside it:

  • D1. Scratch. <brain>/.brain/scratch is bound read-write into the worker as its own mount, created when missing. It must be a real directory inside the brain, never a symlink or redirect. Hard links into the rest of the brain fail across the mount, and the server never follows a symlink when it serves, previews or prunes scratch. The existing flow (brain render --scratch, brain image --scratch, brain scratch prune, a link for the reader) works unchanged. The per-turn BRAIN_WORKER_SCRATCH tmpfs stays as it is.
  • D2. Workspaces. The index-excluded workspace directory is bound read-write, only when it exists, and never the brain root, an ancestor of it or anything holding authoritative documents. Core has no workspace setting, only the always-excluded name workspaces (DEFAULT_EXCLUDE, packages/core/src/lib/config.ts:475-488), so the name is fixed and the directory's existence is the opt-in. A brain-config key is rejected (an agent in a terminal could widen its own future mount); an operator-owned override is a possible later addition.
  • D3. Pre-existing hard links. Before each turn, each area is walked with lstat, counting the names each file's inode has inside it. A file is offending only when its link count exceeds the names found inside, so links wholly within the area (local clones, package stores) are fine. An offending scratch name is unlinked; an offending workspace file, or a walk past the entry cap, leaves workspaces/ read-only for that turn, named in the agent's note and the server log.
  • D4. A writable $HOME for the turn. A per-turn bwrap --tmp-overlay over $HOME: existing configuration still reads, writes are discarded at turn end. The probe verifies it on each turn; where the overlay is unavailable (bubblewrap before 0.11.0, setuid bubblewrap, or a kernel refusing overlayfs in a user namespace) the fallback is XDG_CONFIG_HOME, XDG_CACHE_HOME and XDG_DATA_HOME on per-turn directories under /tmp. Not for the restricted (autonomous) envelope, which is unchanged.
  • D5. Clear errors. An EROFS on a known read-only path names the sandbox rule and the allowed alternative where the product can intercept it (the brain CLI's scratch-capable commands and the agent's instructions). Arbitrary tools are not wrapped.
  • D6. The agent knows its limits up front. A note generated from the same resolved layout that builds the mounts is injected into every turn's agent context, for both backends, and is tested to match the mounts. It names three places: turn temp ($BRAIN_WORKER_SCRATCH, /tmp, $HOME writes), deleted at turn end and never to be linked in a response; persistent scratch (.brain/scratch/, plus workspaces/ for clones), kept across turns and the only non-brain place to link, where anything linked in a response goes; and the brain, canonical.
  • D7. Promote from scratch (a validated server tool copying a scratch file to a named brain path) is stopped: it only matters for the strict profile below and waits for that work.

A separate "governed writable" epic will revise the default for interactive and voice turns (brain writable inside the worker, policy-protected paths read-only, per-turn journals with revert, auditing), with the 0.41 read-only brain as an opt-in strict profile. D1–D6 remain what the strict profile gets; the launcher takes the list of areas as an input so a profile can choose it. Memory persistence (the first comment's point 2) is owned by #1621/#1625. Release: 0.42.0.

Acceptance criteria for the decision

  • D1/D2: from inside a real worker, files written in .brain/scratch/ and an existing workspaces/ persist on the host; write, create, mkdir, rename, hard-link and symlink-write attempts into the rest of the brain fail, observed from outside. A symlinked .brain, .brain/scratch or workspaces is never created through or bound. The integrated proof (tests/policy-write-boundary.test.ts) attacks from inside both areas for both adapters.
  • D3: a hard link wholly inside workspaces/ keeps it writable; one to a file outside makes it read-only, named in the note and server log; a scratch alias of an outside file is unlinked.
  • D4: the overlay discards host-home writes while reads still work; without the overlay the XDG directories are writable and $HOME is read-only. The tests follow the host's bubblewrap version.
  • D5: brain render --scratch and brain scratch prune run on a writable scratch mount; brain render into the read-only brain names --scratch; the file routes refuse a scratch symlink.
  • D6: the note matches the mounts for every layout tested, including the link rule.
  • Each guard has a mutation receipt; selected hosted proof passes.

Verification and contract handoff — 2026-10-11

Source inspected at main 02d4eb0ce37f621764a80636e8ac95b9b4d19d3c. The current workerCommand still ro-binds the brain at packages/ui-sdk/src/server/worker-launcher.ts:135; DEFAULT_EXCLUDE really names workspaces at packages/core/src/lib/config.ts:475-488. The local installed bubblewrap 0.12.0 advertises --tmp-overlay; that help check is not a successful overlay/worker render proof. The older-version/setuid/kernel fallback requirements are supplied by D4 and still need the stated actual-host tests. Read the worker boundary record and preserve the real two-adapter integrated attacks, scratch route/prune alias checks and meaningful mutations. No fresh render or protected-write proof is claimed here.

The approved D1–D6 criteria are complete. Remove needs: design: artifact UI and broader profile/limits interactions now live in the named sibling tasks/epics, not this mechanism. Native parent #1644 is preserved after the maintainer's hierarchy update. Preserve p1 and the recorded 0.42.0 release target; do not assign a milestone or publish from triage. Both governed and strict will consume the named-mount/note mechanism, but this issue alone does not change the default brain profile. Internal layout/context changes need no new consumer schema by implication; assess actual public representations under the contract/version agreement if implementation changes them. Run required local preflight and selected hosted proof for the implementation.

Activity

  1. added
    type: fix
    area: ui-sdk
    area: backends
    priority: p1
    on Oct 11, 2026
  2. schlessera commented on Oct 11, 2026

    @schlessera
    OwnerAuthor

    Two more findings from hosted turns on 0.41.0.

    1. brain render --scratch fails in two layers

    1. With the default $HOME, Chromium doesn't start:
      mkdir: cannot create directory '/root/.local/share/applications': Read-only file system (then chrome_crashpad_handler: --database is required).
    2. With HOME / XDG_CONFIG_HOME / XDG_CACHE_HOME pointed at /tmp, Chromium renders the PDF, but saving it fails:
      EROFS: read-only file system, open '<brain>/.brain/scratch/.<name>-<timestamp>.pdf.<id>.tmp'.

    So the renderer itself works inside the sandbox. Only a writable $HOME and a writable, persistent scratch location are missing. Generating a PDF, image or other file for the user is currently impossible in a hosted turn.

    2. Agent memory written during a turn is silently discarded

    The Claude runtime keeps its auto-memory under the project directory of the config dir (projects/<project>/memory/*.md). That directory is copied into the worker state at turn start, so memory is readable. But persist() only writes back .jsonl transcripts (if (!file.endsWith(".jsonl")) continue;, packages/ui-backend-claude/src/worker-state.ts:79). Any memory file the agent creates or edits during a turn is dropped when the state dir is cleaned up.

    Reproduced: in one turn the agent wrote memory/<name>.md and appended a line to memory/MEMORY.md, and both writes succeeded inside the worker. In every later session, neither the file nor the index line exists. Nothing reports the loss, so the agent believes it saved something.

    Expected: either persist the memory directory (with the same alias/size checks as transcripts), or keep it out of the writable state and tell the agent that memory is read-only in hosted turns. This may deserve its own issue; it sits on the same persist path as #1621 D1, so the design there should decide which non-transcript files under the project directory are carried back.

  3. added
    needs: decision
    area: core
    area: render
    area: ui-server
    on Oct 11, 2026
  4. schlessera commented on Oct 11, 2026

    @schlessera
    OwnerAuthor

    2026-10-11 triage: folded the later two-layer render failure and silently discarded auto-memory report into the active handoff. A bounded real-state fixture reproduced memory loss. Added explicit artifact/workspace authority and memory persistence/read-only choices; preserved the read-only brain, server-owned writes and autonomous isolation instead of selecting writable mounts by implication.

  5. schlessera commented on Oct 11, 2026

    @schlessera
    OwnerAuthor

    Coordination note: finding 2 above (agent memory written during a turn is discarded) is being fixed together with #1621/#1625, because it sits on the same copy/persist path in packages/ui-backend-claude/src/worker-state.ts. That PR copies the project's memory/ folder into the worker state and persists changed memory/*.md notes back with the same alias, byte-bound and concurrent-change checks as transcripts (a note another turn changed meanwhile is refused alone and named). Work on this issue does not need to touch the memory path; finding 1 (writable $HOME and scratch for brain render --scratch) stays here.

  6. schlessera commented on Oct 11, 2026

    @schlessera
    OwnerAuthor

    Request for the generated sandbox-capabilities note in the turn's agent context (maintainer addition, 2026-10-11: the agent should know its limits rather than run into errors). The #1621/#1625 PR implements memory option M2 (parent-validated bounded persistence) per the maintainer's batch instruction. Please include these facts for interactive Claude turns in that note, or expose an input the #1621 PR can feed, rather than a second mechanism:

    • Auto-memory notes persist: a changed or new memory/*.md file directly in the project memory folder is saved after the turn. Subfolders and other file types are not saved, and nothing is deleted. A note another conversation changed during this turn is not overwritten; the turn reports it.
    • Runtime state (this conversation's saved history, memory and settings, plus what the turn writes) has a per-turn budget: the history copied in plus 16 MiB of room to grow, within 128 MiB and within the host's /dev/shm. A conversation whose history no longer fits refuses with session_too_large and is continued in a new conversation.
    • Dynamic, per turn (if your mechanism takes inputs): when the resumed conversation's history is at or above 75% of what a turn can hold, say so with the percentage, so the agent can suggest continuing in a new conversation.

    Autonomous (restricted) turns keep no memory, settings or transcript, so none of this applies to them. I will rebase onto your mechanism if it lands first; if mine lands first, the constants live in packages/ui-backend-claude/src/worker-state-budget.ts.

  7. added
    needs: design
    and removed
    needs: decision
    on Oct 11, 2026
  8. schlessera commented on Oct 11, 2026

    @schlessera
    OwnerAuthor

    2026-10-11 triage: Folded #1636’s approved governed/strict and utility-lifetime rulings into the active brief, and separated the coordinated memory fix. Replaced the settled authority decision with the precise remaining artifact/limits design need; native attachment to #1636 reflects the full deliverable.

  9. 41 remaining items

  10. schlessera commented on Oct 11, 2026

    @schlessera
    OwnerAuthor

    Outcome: merged in #1641 as squash b8862b31ba7ab852e3c8ce1b81eed59e74ca7b3c on main. Its parent is 998810973c, and its tree equals the merge of that base with the tested head 784b4d90. Release: 0.42.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

agent-readyarea: backendsarea: corearea: renderarea: ui-sdkarea: ui-serverpriority: p1type: fix

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions