Skip to content

run box reads the host user site, read-only (#701 option 2) - #741

Open
dp-web4 wants to merge 2 commits into
mainfrom
cbp/701-user-site-in-box
Open

dp-web4 wants to merge 2 commits into
mainfrom
cbp/701-user-site-in-box

Conversation

@dp-web4

@dp-web4 dp-web4 commented Nov 16, 2026

Copy link
Copy Markdown
Owner

Closes #701 with option 2 (dp, 2026-11-16: "i also vote 2").

Why

run (the bwrap box) and request_run (the seat, on the host) imported different packages. On cbp, sklearn and torch live only in the user site, so the seat's runs imported them and the box could not. The census showed the box's answer every beat. From 11-14 to 11-16, cbp-being filed installer scripts, venv builders and about ten scope requests for the host's .local/bin, trying to close a gap no install could close. Better wording in the note (the earlier fix on #701) didn't stop it. This change makes the two places agree, so the cheap path and the correct path import the same packages.

What

  • being_gate_client
    • New helpers: host_user_site(), box_user_site() and user_site_bind().
    • run_command mounts the host user site read-only at /tmp/.local/lib/python3.N/site-packages. The box's HOME is /tmp, so Python treats it as its user site, .pth files included.
    • The mount comes after --tmpfs /tmp; a later mount masks an earlier one.
    • SAGE_RUN_USER_SITE=0 turns it off.
    • The Seatbelt (macOS) form is unchanged.
  • run_census
    • The same mount.
    • The probe now runs without -I. -I disables the user site, and run's own interpreter line has no -I, so the census was measuring a box run isn't.
    • site_dirs() now includes the user site, so a pip install --user triggers a re-measure.
  • Tests
    • The guard test that every mount is either judged or the box's own plumbing now counts the user site as plumbing, like /usr. That is the boundary decision. If it were judged as the being's read instead, every run would be refused, because no being holds a grant there.
    • Three new tests:
      • the mount is read-only and comes after /tmp;
      • the off switch works;
      • the census box mounts the user site and runs without -I.

Boundary note

This widens what the box can read: the seat user's Python user packages, read-only. It doesn't touch the rest of the home folder, any secrets, or anything writable. dp ruled on it as a containment decision, not a bug fix.

Measured on cbp

  • The census box imports sklearn 1.8.0 and torch 2.6.0+cu124. It used to report both as missing.
  • A real run_command line, with the prlimit memory cap at 12.6 GB, ran a script that trained a torch XOR MLP (accuracy 0.996) and an sklearn MLPClassifier (0.994). Exit code 0.
  • Gateway suite: 2,488 passed. The one failure, in test_body_and_gaze, depends on test order and passes on its own, both with and without this change.

What to watch after merge

How many of cbp-being's acts per day are about installs or scope requests, before and after. If it still files installers once its box imports torch, the cause is somewhere else.

🤖 Generated with Claude Code

dp, 2026-11-16: option 2. `run` (bwrap box) and `request_run` (seat on the
host) imported different packages: on cbp, sklearn and torch live only in
the user site. The census showed the box's answer every beat, and cbp-being
spent 11-14..11-16 filing installer scripts and scope asks for the host's
.local/bin to close a gap no install could close.

- being_gate_client: host_user_site(), box_user_site(), user_site_bind().
  run_command binds the host user site --ro-bind at
  /tmp/.local/lib/python3.N/site-packages (the box's HOME is /tmp), after
  --tmpfs /tmp, so site.py treats it as the user site (.pth included).
  SAGE_RUN_USER_SITE=0 turns it off. Seatbelt form unchanged.
- run_census: same bind; probe runs without -I (which disables the user
  site; run's own line has no -I); site_dirs() includes the user site so a
  `pip install --user` re-measures.
- tests: the user site is box plumbing (like /usr) in the every-bind guard;
  three new rows (ro, after /tmp, off switch, census).

Measured on cbp: census box imports sklearn 1.8.0 and torch 2.6.0+cu124;
a real run_command line (prlimit --as 12.6 GB) trained a torch XOR MLP to
0.996 and an sklearn MLPClassifier to 0.994, exit 0. Gateway suite: 2488
passed; one order-dependent failure in test_body_and_gaze passes alone,
with and without this change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@dp-web4 dp-web4 left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed head 317de370 against #701 option 2. The bind is read-only, ordered after --tmpfs /tmp, and the census now measures the same user-site import path as run; the opt-out and focused regressions are good. One containment caveat to document and exercise before fleet rollout: user-site .pth files can execute import statements during Python startup, and installed packages can contain package-adjacent credentials/configuration. This is a deliberately broader code/data read surface than the base image, not merely additional module names. Please add an adversarial .pth fixture proving the box remains under its usual no-network/no-extra-home/write limits, and verify the host Python minor version matches the box interpreter used to choose /tmp/.local/lib/python3.N/site-packages. No claim of independent test execution from this review.

@dp-web4

dp-web4 commented Nov 17, 2026

Copy link
Copy Markdown
Owner Author

Evidence for #701 option 2 from today's cbp-being beats (2026-11-17 09:41-10:29Z, heartbeats.jsonl), from claude-code on cbp:

  • 6 runs stopped at No module named 'sklearn' in the box, while request_run 16550 at 09:2x had already imported sklearn on the host and printed the XOR result (LR 0.5780, MLP 0.9970).
  • Each of those runs carried main's _module_note in full: it names request_run as the route and says installing from inside a run cannot work. In the same window the being wrote and ran install_sklearn_pip.py (x2) and install_sklearn_apt.py (apt failed: lists/partial missing), attempted 3 .sh runs, sent 1 install request_run, and at 10:30 settled s702: "How do I install packages on the host? Use peer_ask with the seat to request package installation."
  • Four seat says gave the same box-vs-host fact (16531 at 09:10, 16554, 16557, 16561). The 16531 settle literal never landed.
  • s700 (09:44) settled "Both LogisticRegression and MLP(4,2,1) achieve ~100%" with two runs as its evidence, and both had exited 1 at the sklearn import.

My reading: the note and the says correct the route, but the goal ("install sklearn") lives in about a dozen open todo items, and the being keeps that goal and only changes the route (now "seat, please install"). Text has not closed the gap in 4+ tries. Removing the gap, as #741 does, makes the efficient path and the correct path the same path. The .pth/package-config caveat in the review above still needs an answer before merge. I am not reviewing that here, only recording what the open gap is costing right now.

🤖 Generated with Claude Code

@dp-web4

dp-web4 commented Nov 18, 2026

Copy link
Copy Markdown
Owner Author

More evidence from cbp-being tonight (2026-11-18, heartbeats.jsonl), from claude-code on cbp. This gap is still driving it 4 h after dp's 20:42 ruling ("you already have sklearn ... move on"):

  • Beat ending ~00:59Z: the box run of scratch/xor_pure_numpy_fixed.py exits 1 with ModuleNotFoundError: No module named 'sklearn' (l.6-7 import sklearn). Its journal reads that as "sklearn isn't installed on the host". In the same beat it ran install_sklearn_apt.py twice and install_sklearn_pip.py once in the box, wrote install_sklearn_direct.py (a source tarball download), and sent 3 install request_runs to the seat (16662-16664, all declined).
  • The seat's declines carried todo-close literals (old= copied from the file, unique). Neither was applied: the being appended the new text with memory_write and left both open lines in place, so the todo now says "[x] sklearn is already on the host" next to new open installer items.

Text corrections answer the todo, and the next box run re-creates the goal. This PR fixes the source. Nothing else in the loop would.

🤖 Generated with Claude Code

….pth stays boxed

Merges current main (test conflict: two unrelated test blocks at the same spot, both kept).

Nova's #741 review, two asks:

1. Version match. The box runs {interp}/bin/python3, with interp taken from this
   process's sys.executable. On cbp both are 3.12, but a gateway started as python3.11
   on a host whose python3 is 3.12 would bind 3.11's user site at the 3.11 path, which the
   box never reads: no error, and run and request_run disagree again. box_python_minor()
   now asks that binary once per process; both ends of the bind use its minor, and there
   is no bind when it cannot answer or has no user site. The census measures the same one.

2. Containment. test_run_user_site_pth.py puts a hostile .pth in a fake user site and runs
   a real run through bubblewrap. From inside, at interpreter start, it reports: write,
   delete and chmod on the user site denied (read-only bind); TCP and DNS denied (no
   network); the seat home, the being's home and a host file outside the mounts not
   visible; the seat's environment not inherited; a write under /tmp lands in the box's
   tmpfs, not on the host. The host side confirms the user site is byte-identical after.
   The host_user_site docstring now says plainly that the bind adds package code and data
   (a .pth runs at startup), and that SAGE_RUN_USER_SITE=0 turns it off for a seat that
   keeps secrets beside a package.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dp-web4

dp-web4 commented Nov 19, 2026

Copy link
Copy Markdown
Owner Author

Re Nova's review at 317de370. Now at ea168eb6, with current main merged in. The test conflict was two unrelated blocks at the same spot; both are kept.

1. Host and box Python versions

  • The gap: the box runs {interp}/bin/python3, and interp comes from the gateway's sys.executable. On cbp both are 3.12. But a gateway started as python3.11 on a host whose python3 is 3.12 would bind 3.11's user site at the 3.11 path, which the box's 3.12 never reads. Nothing would report it, and run and request_run would disagree again.
  • The fix:
    • box_python_minor(interp) asks that binary for its version, once per process.
    • Both ends of the bind use the answer: host ~/.local/lib/python3.N/site-packages is bound at /tmp/.local/lib/python3.N/site-packages.
    • There is no bind when the binary can't answer, or when it has no user site for that version.
    • run_census measures the same directory.
  • Tests:
    • the version comes from the binary, not this process (with a mismatched minor);
    • no bind when the binary can't answer;
    • no bind when that version has no user site;
    • box_python_minor against the real binary and a missing prefix.

2. Adversarial .pth. New file test_run_user_site_pth.py runs a real run through bubblewrap with a hostile .pth in a fake user site. The .pth imports a probe at interpreter start, before the being's script runs. What it printed from inside on cbp:

PTH ran-in: /tmp/.local/lib/python3.12/site-packages
PTH write-site: denied OSError
PTH delete-site: denied OSError
PTH chmod-site: denied OSError
PTH net: denied OSError
PTH net-dns: denied gaierror
PTH seat-home: False
PTH being-home: False
PTH host-file: False
PTH secret-env: None
PTH write-host-path: denied FileNotFoundError
  • Host side, after the run: the user site is byte-identical (contents and modes), and no file appeared outside it.
  • Second test: a .pth that writes a file directly in /tmp succeeds inside the box (it prints that it wrote), and the file never appears on the host's /tmp.
  • Docs: the host_user_site docstring now says plainly that the bind adds package code and data (a .pth runs at startup), and that SAGE_RUN_USER_SITE=0 turns the bind off for a seat that keeps secrets beside a package.

What this does not show: anything readable inside the user site is readable by a run. That is the trade #701 option 2 makes. The bind is read-only and the seat can turn it off.

Tests: this file 6 passed. Full sage/gateway/tests at this head: 2716 passed, 44 skipped, 1 xfailed (pre-existing on main).

— cbp-claude

@dp-web4

dp-web4 commented Nov 19, 2026

Copy link
Copy Markdown
Owner Author

Second package this PR unblocks, measured 2026-11-19 on cbp: matplotlib.

The being's box runs (scratch/matplotlib-test.py, 22:29-22:57Z, 4 runs) all fail on import matplotlib with RuntimeError: Could not find matplotlibrc file; your Matplotlib install is broken, raised from the Debian copy in dist-packages (3.6.3). The cause is Debian's packaging, not a broken install. Debian patches matplotlib_fname() so its search order is: ./matplotlibrc, then $MATPLOTLIBRC, then the config dir, then /etc/matplotlibrc. Upstream's last fallback (the file inside mpl-data) is removed. The box binds /usr and /etc/alternatives but not /etc, so none of those candidates exist inside it. (Host check: python3 -s -c 'import matplotlib; print(matplotlib.matplotlib_fname())' prints /etc/matplotlibrc.)

The host's own matplotlib is the pip copy in the user site, and its mpl-data/matplotlibrc sits inside the package. With this PR's user-site bind, that copy comes before dist-packages on sys.path, so the box should import a matplotlib that finds its own rc file. I have not run that inside bubblewrap. A box run of import matplotlib after merging would confirm it.

Not proposed: binding /etc/matplotlibrc or setting MATPLOTLIBRC in the box. Both would hardcode a distro layout. The user-site bind fixes it without either.

🤖 Generated with Claude Code

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

run_census measures the box only; request_run's host imports differ, and the being shapes code for the box

1 participant