Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions sage/gateway/being_gate_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1980,6 +1980,14 @@ def run_command(args: dict, ctx: Optional[dict] = None) -> str:
f"{grant_binds}"
# Writable in there: these two size-limited tmpfs, and what the being's grants reach.
f" --size {RUN_WORK_BYTES} --tmpfs /work{inputs}"
# THE ROOT IS READ-ONLY, LAST, AFTER EVERY MOUNT. bwrap's root is a writable tmpfs, so a write
# to a path nothing is mounted at landed there and succeeded. sprout-being, 2026-11-19 20:32Z: a
# script appended a user entry to the system user list and made a home directory; both "worked",
# the run printed that the user was created, and the beat took it as done and reopened a settled
# conclusion that said it could not be. Nothing on the machine had changed. Read-only, such a
# write fails as "Read-only file system" in the run itself. Remounting / changes only the root
# mount: /tmp, /work and the grant binds are mounts of their own and keep their mode.
" --remount-ro /"
" --unshare-pid --unshare-net --unshare-ipc --unshare-uts"
" --new-session --die-with-parent"
" --setenv HOME /tmp --setenv PYTHONUTF8 1 --setenv PYTHONDONTWRITEBYTECODE 1"
Expand Down
4 changes: 3 additions & 1 deletion sage/gateway/hestia_dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -5644,7 +5644,9 @@ def _shown(how):
"can mount. ")
+ "Any other path, your home included, does not exist in there, so a check like "
"os.path.exists() is False for it whatever is on disk; memory_read answers about "
"the disk.")
"the disk. Outside /tmp, /work and what is WRITABLE above, nothing in there can be "
"written: a write elsewhere (/etc/passwd, /home/...) fails as 'Read-only file system', "
"so a run cannot change those files on this machine.")
if skipped:
text += " Not mounted: " + "; ".join(f"{p} ({why})" for p, why in skipped) + "."
return text
Expand Down
27 changes: 27 additions & 0 deletions sage/gateway/tests/test_run_verb.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,33 @@ def test_both_writable_places_are_size_bounded_from_inside(tmp_path, monkeypatch
assert "CHANGED-INSIDE" not in (home / "scratch" / "fill.py").read_text()


@needs_bwrap
def test_a_write_outside_the_writable_places_fails_in_the_run_itself(tmp_path):
"""sprout-being, 2026-11-19 20:32Z: a script appended a user entry to /etc/passwd and made a home under
/home. bwrap's root was a writable tmpfs, so both succeeded in there, the run printed that the user was
created, and the beat took it as done. The root is now read-only: the write fails where it is made."""
d, home = _run_dispatcher(tmp_path)
(home / "scratch" / "w.py").write_text(
"import os\n"
"def w(p):\n"
" try:\n"
" os.makedirs(os.path.dirname(p), exist_ok=True)\n"
" with open(p, 'a') as f:\n"
" f.write('x\\n')\n"
" return 'WROTE'\n"
" except OSError as e:\n"
" return 'refused ' + (e.strerror or '')\n"
"for p in ('/etc/passwd', '/home/test-user/.profile', '/opt/x', '/tmp/t', '/work/k'):\n"
" print(p, w(p))\n")
r = d._do_run(BeingIntent("run", {"path": "scratch/w.py"}))
assert r.ok, r.error
out = r.result["stdout"]
for p in ("/etc/passwd", "/home/test-user/.profile", "/opt/x"):
assert f"{p} refused Read-only file system" in out, out
assert "/tmp/t WROTE" in out and "/work/k WROTE" in out, out
assert "fails as 'Read-only file system'" in r.result["note"], r.result["note"]


@needs_sandbox
def test_output_goes_to_capped_files_and_only_head_and_tail_come_back(tmp_path, monkeypatch):
"""capture_output read everything into the seat (outside every limit) before trimming it."""
Expand Down
Loading