oliver-zehentleitner / maity

runner: a Claude Code placement gets its own temp directory under the default workspaces path

Sign in to report

tsk-k7svzz2p4v7y Done An agent

Under the default ~/maity-workspaces, a Claude Code placement's scratch tmp is too long for the socket rule (cli/src/maity/runner/adapters.py, SOCKET_PATH_MAX). The session therefore starts without a TMPDIR, and its tools' and Claude Code's own temporary files go to the shared /tmp, which every placement of the same OS user can see. #2068 (tsk-0zb9mgzmbwn4) fixed this for Codex only, with a short 0700 leaf under the hidden per-user scratch parent in /tmp. KtW cli/context/runner.md 893d9dfd records why Claude Code was left out.

Already ruled out (KtW 893d9dfd, live check 2026-11-20, Claude Code 2.1.329):

  • Codex's leaf for Claude Code: inside the parent in denyRead and denyWrite, an allowWrite and allowRead on the leaf make it visible but mount it read-only.
  • Dropping the parent from denyWrite, or any wider allow (the parent, /tmp): under one OS user a sibling leaf's 0700 separates nothing, so placements could write each other's temp files.
  • A per-user parent that no sandbox hides, with random leaves: same-user sandboxed placements could list it and reach each other's files.

Still open, to check first:

  • CLAUDE_CODE_TMPDIR in the scratch, independent of the socket rule. It covers Claude Code's own temporary files. Check whether it also moves the sandbox socket, so that TMPDIR could then be the scratch's tmp whatever its length; if not, say what the tools' TMPDIR becomes.
  • Whether a newer pinned Claude Code honours an allowWrite on a leaf inside a denyWrite parent (KtW 893d9dfd's revisit-when). If so, Codex's leaf applies unchanged: extend workspace.OWN_TMPDIR_HARNESSES and add the leaf to Claude Code's settings.

Done when:

  • A Claude Code placement under the default path has its own temporary directory, mode 0700, out of reach of every other placement as the scratch is, and removed with the placement. Or, if only Claude Code's own files can be moved, a KtW entry says so and why, and what the tools' temporary files do.
  • No sandbox gets a wider allow than today's.
  • Tests for the generated Claude Code settings and environment, and the path length against the socket limit.
  • docs/runners.md (scratch section) and KtW 893d9dfd updated (superseded or amended).
  • A live check by ops on a runner with the pinned Claude Code: a sandboxed command writes its temp directory, cannot reach a sibling placement's, and nothing is left after Remove.

Security leg on the PR.

Notes

  1. Mr. Robot · Nov 21, 2026, 11:29 UTC

    ops 3yc2, gate-3 live mirror check for PR #2084 at its own head f2aea0e8, steps 1–4. oliver-pc01-l, 2026-11-21 11:28Z, Claude Code 2.1.329, sandbox on.

    Rig:

    • two TEST placements A and B of a throwaway project under the default ~/maity-workspaces (16-char ids);
    • each got a leaf /tmp/maity-scratch-1001/<32 hex>, made 0700 with tmp in it as _tmp_scratch makes one, and Context.tmpdir = <leaf>/tmp;
    • the env and settings are the PR's own from adapters.launch(), unchanged except main's plaincall PreToolUse hook (my interpreter can't import maity; it judges only maity lines).

    private_tmpdir_refusal(ctx) returned None for both. The generated values per placement:

    • TMPDIR=<leaf>/tmp, CLAUDE_CODE_TMPDIR=<leaf>;
    • allowRead == [<leaf>/tmp], allowWrite == [<scratch>, <leaf>/tmp];
    • the parent in denyRead only. All as you describe.

    Results (A, then B as the mirror; the same for both):

    1. Pass. $TMPDIR = <own leaf>/tmp/claude-1001 (Claude Code appends its subdir). touch "$TMPDIR/a": ok. mktemp and mktemp -p "$TMPDIR": ok, both in <leaf>/tmp/claude-1001/.
    2. Pass. For the other leaf by its known path: touch …/tmp/x rc 1, ls -la <leaf> rc 2, mkdir …/tmp/d rc 1, all with No such file or directory. From outside, the other leaf was unchanged.
    3. Pass, as in P4. ls -la of the parent shows a 0755 tmpfs (size 60) holding only the own leaf. mkdir <parent>/newdir-a returns ok but lands in that tmpfs: nothing appeared outside. touch/mkdir in /tmp: Read-only file system.
    4. Fails for `claude-<uid>/`; passes for `cc-socks/`. From outside, both appear beside tmp in the leaf.
    • cc-socks/: not visible inside. ls and touch give No such file or directory.
    • <leaf>/claude-1001/: visible, readable and writable inside. ls -la shows its contents (the project dir, bash-edit-diff, plugin-tool-staging, fswatch-probe-*), and find reads its files. `touch <leaf>/claude-1001/x` returned ok, and `x` was there from outside afterwards: a real write.

    Inside, the leaf is itself a tmpfs view (size 80) with only tmp and claude-1001 bound in. claude-1001 is not in the generated allowWrite, so Claude Code itself opens its own temp dir under CLAUDE_CODE_TMPDIR to its sandbox. That also answers P2's open question. That dir holds the session's tasks/*.output and the cwd files. It is private to the placement now (B couldn't reach A's), but the placement's own commands can rewrite what Claude Code reads back.

    1. and 6. (the leaf gone after Remove, and the refusal case): not run yet. Both need the real supervisor starting and removing placements, i.e. a local hub and a runner from this branch, with their own state, config and tmux socket. I've asked lotse for a go on that setup; it takes about 30–60 min.

    Cleaned up: both leaves (the parent is empty again), the throwaway project, its ~/.claude/projects entries, and nothing g3-* in /tmp. Cost: 2 small headless prompts on maity-runner's Claude login. Log (no secrets): ~/ops-workspace/tmp/probe2084.log on the PC.

  2. Mr. Robot · Nov 21, 2026, 11:33 UTC

    ops 3yc2, the check ugmc asked for (seq 186785): <leaf>/claude-<uid>/ with step 1's own settings, PR #2082 at 87c6c279. Same rig as the #2084 gate-3 run: two TEST placements A and B, the default ~/maity-workspaces, Claude Code 2.1.329, sandbox on, adapters.launch() from that head unchanged except main's plaincall hook. oliver-pc01-l, 2026-11-21 11:31–11:32Z.

    Generated per placement:

    • CLAUDE_CODE_TMPDIR=<leaf>/tmp, TMPDIR unset;
    • no allowRead, no allowWrite for the leaf;
    • the parent in denyRead and denyWrite.

    From outside, Claude Code put claude-1001/ and cc-socks/ in `<leaf>/tmp/`, not beside tmp as in #2084.

    From each sandbox (the same for A and B):

    • `<leaf>/tmp/claude-1001/`: visible and readable, but read-only.
    • ls -la <leaf>/tmp shows claude-1001.
    • ls -la <leaf>/tmp/claude-1001 lists the project dir, bash-edit-diff, plugin-tool-staging and fswatch-probe-*.
    • touch <leaf>/tmp/claude-1001/x: Read-only file system, rc 1.

    So it's allow-under-deny as in P3: Claude Code's own opening of its temp dir survives the parent's deny as a read-only bind. It is not hidden.

    • <leaf>/tmp/cc-socks/: hidden (No such file or directory).
    • The sandboxed $TMPDIR is /tmp/claude-1001, the shared one, writable (touch, mktemp), as in P2. That's the known gap #2082 names.
    • The other leaf by its known path: No such file or directory for touch, ls and mkdir. The parent is a tmpfs with only the own leaf. /tmp is read-only.

    So the KtW line "stays hidden from its sandboxed commands" overstates for `claude-<uid>/`: that dir is readable (not writable) by the placement's own commands. cc-socks/ is hidden.

    Cleanup: both leaves, the throwaway project, its ~/.claude/projects and /tmp/claude-1001 project dirs, and my 6 test files in /tmp/claude-1001 (by their exact names). Cost: 2 small headless prompts on maity-runner's Claude login. Log: ~/ops-workspace/tmp/probe2082.log on the PC.

  3. Maity Test Team · Nov 21, 2026, 12:54 UTC

    Tester note (maity-test-team#mmza): deployed #2082 (step 1) at main bc824336, tested headless from the clone. PASS, no bug filed.

    Ran

    • cli/tests/test_adapters.py + test_supervisor.py: 505 passed.
    • adapters.launch() / claude_settings() with a throwaway probe test (removed after), default-root scratch under /home/oliver.zehentleitner and /Users/oliverzehentleitner, 16-char placement id, leaf under /tmp/maity-scratch-1001:
    • Claude Code: env has only CLAUDE_CODE_TMPDIR=<leaf>/tmp, no TMPDIR; settings keep the parent in denyRead and denyWrite, no allowRead, the leaf in no allowWrite.
    • Codex unchanged: TMPDIR=<leaf>/tmp, no CLAUDE_CODE_TMPDIR.
    • cc-socks/4194304.sock under the longest leaf: 88 bytes (Linux, uid 2^32-1, limit 107), 90 bytes (macOS /private/tmp, uid 9999, limit 103).
    • The tmp subdir the variable names is made by scratchop.tmp_make, so it exists at start.

    Nit (no card)

    • The PR text says CLAUDE_CODE_TMPDIR=<leaf> and <leaf>/claude-<uid>/; the code sets <leaf>/tmp, so Claude Code's files land in <leaf>/tmp/claude-<uid>/. It's the same leaf and removed with it. Only matters for ops' live check paths.

    Not covered

    • A live Claude Code placement (the PR's live check: claude-<uid>/ and cc-socks/ appear, the sandbox runs, the leaf is gone after Remove): ops.
    • Step 2 (tools' $TMPDIR, tsk-z5c3798r1ces) is not in this merge.
  4. Maity Test Team · Nov 21, 2026, 13:39 UTC

    Tester note (maity-test-team#mmza): deployed #2084 (step 2) at main f0f1a15a, tested headless from the clone. PASS, no bug filed.

    Ran

    • cli/tests/test_adapters.py + test_supervisor.py: 507 passed.
    • adapters.launch(), claude_settings() and private_tmpdir_refusal() with a throwaway probe test (removed after). Default-root scratch under /home/oliver.zehentleitner, 16-char id, leaf under /tmp/maity-scratch-1001:
    • sandboxed with a leaf: TMPDIR=<leaf>/tmp, CLAUDE_CODE_TMPDIR=<leaf>; allowRead=[<leaf>/tmp], allowWrite=[scratch, <leaf>/tmp]; the parent in denyRead only; no sibling leaf opened; not refused.
    • sandboxed, no leaf: neither variable, the parent in both denies, refused with a clear log text naming the cause and the /srv/mw remedy. Same with no scratch at all.
    • unsandboxed, no leaf: not refused (as designed).
    • roomy scratch (/srv/mw): TMPDIR=<scratch>/tmp, no CLAUDE_CODE_TMPDIR, the parent in both denies, not refused.
    • My step-1 nit (<leaf> vs <leaf>/tmp) is moot now: CLAUDE_CODE_TMPDIR is the leaf itself, as this PR says.

    Not covered

    • A live sandboxed Claude Code placement (ops' P3/P4 probes stand for that), an ssh target, and the macOS uid-over-four-digits refusal: on Linux the socket limit is 107, so that case can't be reproduced here.