The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(file-sync): bound sync-back leaks by owner PID, make the cap overridable, cover every tar backend
teknium1d007afe130e0
diff --git a/tests/tools/test_file_sync_back.py b/tests/tools/test_file_sync_back.pyindex e513ce625a4..e913e0905f0 100644--- a/tests/tools/test_file_sync_back.py+++ b/tests/tools/test_file_sync_back.py@@ -4,6 +4,8 @@ import ioimport loggingimport osimport signal+import subprocess+import sysimport tarfileimport tempfileimport time@@ -29,6 +31,13 @@ from tools.environments.file_sync import (# Helpers# ---------------------------------------------------------------------------++def _dead_pid() -> int:+ """PID of a child that has already been reaped."""+ proc = subprocess.Popen([sys.executable, "-c", "pass"], stdin=subprocess.DEVNULL)+ proc.wait()+ return proc.pid+def _make_tar(files: dict[str, bytes], dest: Path):"""Write a tar archive containing the given arcname->content pairs."""with tarfile.open(dest, "w") as tar:@@ -137,49 +146,28 @@ class TestStaleSyncBackTempCleanup:mgr = _make_manager(tmp_path, bulk_download_fn=download)mgr.sync_back()- assert seen["tar"].name.startswith(_SYNC_BACK_TEMP_PREFIX)+ assert seen["tar"].name.startswith(f"{_SYNC_BACK_TEMP_PREFIX}{os.getpid()}-")assert not leaked.exists()assert list(tmp_root.iterdir()) == []- def test_dead_owner_entry_reclaimed_regardless_of_age(self, tmp_path, monkeypatch):- """#114437: an entry whose owner PID is gone is reclaimed immediately — age (and the- staging-dir mtime freeze during extraction) must not keep a leaked multi-GB tar around."""- entry = tmp_path / f"hermes-sync-back-{os.getpid()}-xyz.tar"- entry.write_bytes(b"x")- fresh = time.time()- os.utime(entry, (fresh, fresh))- monkeypatch.setattr("tools.environments.file_sync._pid_alive", lambda pid: False)-- assert _cleanup_stale_sync_back_temp(tmp_path) == 1- assert not entry.exists()-- def test_live_owner_entry_survives_any_age(self, tmp_path, monkeypatch):- """An entry owned by a live process (this one, or a concurrent gateway under a- different HERMES_HOME) is never reclaimed, however old its mtime looks."""- entry = tmp_path / f"hermes-sync-back-{os.getpid()}-xyz.tar"- entry.write_bytes(b"x")- os.utime(entry, (0, 0))- monkeypatch.setattr("tools.environments.file_sync._pid_alive", lambda pid: True)-- assert _cleanup_stale_sync_back_temp(tmp_path) == 0- assert entry.exists()-- def test_new_temp_entries_embed_the_owner_pid(self, tmp_path):- """Fresh temp entries carry the owning PID so the sweep can judge ownership (#114437)."""- seen = {}-- def download(dest: Path):- seen["tar"] = dest- _make_tar({"root/.hermes/x.txt": b"hi"}, dest)+ def test_owner_liveness_decides_before_age(self, tmp_path):+ """A hard-killed owner's fresh entry is reclaimed at once; a live owner's fresh entry and+ a legacy (no-PID) fresh entry are kept; a live owner's entry past the cutoff still goes+ (a recycled PID must not pin a leak forever)."""+ dead_fresh = tmp_path / f"{_SYNC_BACK_TEMP_PREFIX}{_dead_pid()}-a.tar"+ live_fresh = tmp_path / f"{_SYNC_BACK_TEMP_PREFIX}{os.getpid()}-b"+ legacy_fresh = tmp_path / f"{_SYNC_BACK_TEMP_PREFIX}legacy.tar"+ live_old = tmp_path / f"{_SYNC_BACK_TEMP_PREFIX}{os.getpid()}-c.tar"+ for path in (dead_fresh, legacy_fresh, live_old):+ path.write_bytes(b"x")+ live_fresh.mkdir()+ old = time.time() - _SYNC_BACK_STALE_SECONDS - 60+ os.utime(live_old, (old, old))- mgr = _make_manager(tmp_path, bulk_download_fn=download)- mgr.sync_back()+ assert _cleanup_stale_sync_back_temp(tmp_path) == 2- name = seen["tar"].name- assert name.startswith(f"{_SYNC_BACK_TEMP_PREFIX}{os.getpid()}-")- from tools.environments.file_sync import _temp_entry_owner_pid- assert _temp_entry_owner_pid(name) == os.getpid()- assert _temp_entry_owner_pid("hermes-sync-back-legacy.tar") is None+ assert not dead_fresh.exists() and not live_old.exists()+ assert live_fresh.exists() and legacy_fresh.exists()# ---------------------------------------------------------------------------@@ -551,14 +539,23 @@ class TestSyncBackSizeCap:mgr.sync_back(hermes_home=tmp_path / ".hermes")assert Path(host_file).read_bytes() == b"remote_version"- def test_stale_sweep_window_is_bounded_to_half_an_hour(self):- """A hard-kill crash loop must not accumulate tars for hours before reclaim (#114437).+ def test_cap_override_env_raises_the_cap(self, tmp_path, monkeypatch, caplog):+ """HERMES_SYNC_BACK_MAX_BYTES overrides the 2 GiB default; a non-integer value is+ ignored with a warning and the default applies."""+ host_file = _write_file(tmp_path / "host_skill.md", b"original")+ files = {"root/.hermes/skill.md": b"remote_version"}+ mgr = _make_manager(tmp_path, file_mapping=[(host_file, "/root/.hermes/skill.md")],+ bulk_download_fn=_make_download_fn(files))++ monkeypatch.setenv("HERMES_SYNC_BACK_MAX_BYTES", "1")+ mgr.sync_back(hermes_home=tmp_path / ".hermes")+ assert Path(host_file).read_bytes() == b"original" # 1-byte cap: skipped- The cutoff only governs legacy (pre-PID) names and Windows hosts — owned entries- are reclaimed by owner liveness instead — but it still bounds a crash loop's- leftovers from an older build.- """- assert _SYNC_BACK_STALE_SECONDS <= 30 * 60+ monkeypatch.setenv("HERMES_SYNC_BACK_MAX_BYTES", "lots")+ with caplog.at_level(logging.WARNING, logger="tools.environments.file_sync"):+ mgr.sync_back(hermes_home=tmp_path / ".hermes")+ assert Path(host_file).read_bytes() == b"remote_version" # default cap applies+ assert any("HERMES_SYNC_BACK_MAX_BYTES" in r.message for r in caplog.records)class TestSyncBackWindowsHost:diff --git a/tests/tools/test_sync_back_backends.py b/tests/tools/test_sync_back_backends.pyindex 61d54ab2f7e..c99c1c7e708 100644--- a/tests/tools/test_sync_back_backends.py+++ b/tests/tools/test_sync_back_backends.py@@ -131,66 +131,35 @@ class TestSSHBulkDownload:call_kwargs = mock_run.call_argsassert call_kwargs.kwargs.get("timeout") == 120 or call_kwargs[1].get("timeout") == 120- def test_ssh_bulk_download_excludes_sockets(self, ssh_mock_env, tmp_path):- """The remote tar must skip live sockets — gateway.sock cannot be archived (#114437)."""- dest = tmp_path / "backup.tar"-- with patch.object(subprocess, "run", return_value=subprocess.CompletedProcess([], 0)) as mock_run:- ssh_mock_env._ssh_bulk_download(dest)-- cmd_str = " ".join(mock_run.call_args[0][0])- assert "--exclude='*.sock'" in cmd_str-- def test_ssh_bulk_download_tolerates_socket_ignored_exit_2(- self, ssh_mock_env, tmp_path- ):- """rc=2 whose stderr is only 'socket ignored' lines must not fail the transfer (#114437)."""+ def test_ssh_bulk_download_tolerates_only_socket_ignored_exit_2(self, ssh_mock_env, tmp_path):+ """Live sockets are excluded up front, and an rc=2 whose stderr is solely+ 'socket ignored' lines (a socket not named *.sock) does not fail the transfer."""dest = tmp_path / "backup.tar"stderr = b"tar: home/testuser/.hermes/gateway.sock: socket ignored\n"completed = subprocess.CompletedProcess([], 2, stderr=stderr)- with patch.object(subprocess, "run", return_value=completed):+ with patch.object(subprocess, "run", return_value=completed) as mock_run:ssh_mock_env._ssh_bulk_download(dest) # must not raise- def test_ssh_bulk_download_fails_on_other_exit_2_errors(self, ssh_mock_env, tmp_path):- """rc=2 reporting anything besides an ignored socket still fails the transfer."""- from tools.environments.base import EnvironmentConnectionError- dest = tmp_path / "backup.tar"- stderr = (b"tar: home/testuser/.hermes/gateway.sock: socket ignored\n"- b"tar: home/testuser/.hermes/state.db: Cannot open: Permission denied\n")- completed = subprocess.CompletedProcess([], 2, stderr=stderr)-- with patch.object(subprocess, "run", return_value=completed):- with pytest.raises(EnvironmentConnectionError):- ssh_mock_env._ssh_bulk_download(dest)+ assert "--exclude='*.sock'" in " ".join(mock_run.call_args[0][0])- def test_ssh_bulk_download_fails_on_exit_1_and_bare_exit_2(- self, ssh_mock_env, tmp_path- ):- """rc=1, and rc=2 with no diagnostic at all, still fail the transfer."""+ def test_ssh_bulk_download_still_fails_on_every_other_status(self, ssh_mock_env, tmp_path):+ """rc=1; rc=2 with a real error beside the socket line, with no diagnostic at all, or+ with 'socket ignored' merely inside a filename — all still raise."""from tools.environments.base import EnvironmentConnectionErrordest = tmp_path / "backup.tar"failures = (- subprocess.CompletedProcess([], 1, stderr=b"ssh: connect to host refused"),- subprocess.CompletedProcess([], 2, stderr=b""),- subprocess.CompletedProcess([], 2, stderr=b"\n"), # whitespace-only is bare too+ subprocess.CompletedProcess([], 1, stderr=b"tar: home/testuser/.hermes/state.db: file changed as we read it"),+ subprocess.CompletedProcess([], 2, stderr=(b"tar: home/testuser/.hermes/gateway.sock: socket ignored\n"+ b"tar: home/testuser/.hermes/state.db: Cannot open: Permission denied\n")),+ subprocess.CompletedProcess([], 2, stderr=b"\n"),+ subprocess.CompletedProcess([], 2, stderr=b"tar: socket ignored dir/state.db: Cannot open: Permission denied\n"),)for completed in failures:with patch.object(subprocess, "run", return_value=completed):with pytest.raises(EnvironmentConnectionError):ssh_mock_env._ssh_bulk_download(dest)- def test_ssh_bulk_download_anchor_rejects_midline_marker(self, ssh_mock_env, tmp_path):- """A diagnostic merely containing 'socket ignored' mid-line is not tolerated."""- from tools.environments.base import EnvironmentConnectionError- dest = tmp_path / "backup.tar"- stderr = b"tar: socket ignored dir/state.db: Cannot open: Permission denied\n"- completed = subprocess.CompletedProcess([], 2, stderr=stderr)-- with patch.object(subprocess, "run", return_value=completed):- with pytest.raises(EnvironmentConnectionError):- ssh_mock_env._ssh_bulk_download(dest)-class TestSSHCleanup:"""Verify SSH cleanup() calls sync_back() before closing ControlMaster."""@@ -288,7 +257,7 @@ class TestModalBulkDownload:assert args[1] == "-c"assert "tar cf -" in args[2]assert "-C / root/.hermes" in args[2]- # Live sockets cannot be archived; exclude them like the SSH backend (#114437).+ # Live sockets cannot be archived; exclude them like the SSH backend.assert "--exclude='*.sock'" in args[2]@@ -361,7 +330,7 @@ class TestDaytonaBulkDownload:assert env._sandbox.process.exec.call_count == 2tar_cmd = env._sandbox.process.exec.call_args_list[0][0][0]assert "tar cf" in tar_cmd- # Live sockets cannot be archived; exclude them like the SSH backend (#114437).+ # Live sockets cannot be archived; exclude them like the SSH backend.assert "--exclude='*.sock'" in tar_cmd# PID-suffixed temp path avoids collisions on sync_back retryassert "/tmp/.hermes_sync." in tar_cmddiff --git a/tools/environments/daytona.py b/tools/environments/daytona.pyindex 3d839acb742..06dda008e02 100644--- a/tools/environments/daytona.py+++ b/tools/environments/daytona.py@@ -111,8 +111,7 @@ class DaytonaEnvironment(BaseEnvironment):rel_base = f"{self._remote_home}/.hermes".lstrip("/")# PID-suffixed remote temp path avoids collisions if sync_back runs concurrently.remote_tar = f"/tmp/.hermes_sync.{os.getpid()}.tar"- # --exclude: live sockets cannot be archived ("socket ignored"), and on tar builds- # that make the skipped socket fatal would fail the download (#114437).+ # --exclude: live sockets cannot be archived ("socket ignored") and must not fail the download.self._sandbox.process.exec(f"tar cf {shlex.quote(remote_tar)} --exclude='*.sock' -C / {shlex.quote(rel_base)}")self._sandbox.fs.download_file(remote_tar, str(dest))diff --git a/tools/environments/file_sync.py b/tools/environments/file_sync.pyindex 547b73d03cd..5fe54171578 100644--- a/tools/environments/file_sync.py+++ b/tools/environments/file_sync.py@@ -48,58 +48,56 @@ GetFilesFn = Callable[[], list[tuple[str, str]]] # () -> [(host_path, remote_pa_SYNC_BACK_MAX_RETRIES = 3_SYNC_BACK_BACKOFF = (2, 4, 8) # seconds between retries_SYNC_BACK_MAX_BYTES = 2 * 1024 * 1024 * 1024 # 2 GiB — refuse to extract larger tars+_SYNC_BACK_MAX_BYTES_ENV = "HERMES_SYNC_BACK_MAX_BYTES"_SYNC_BACK_TEMP_PREFIX = "hermes-sync-back-"# A sync-back temp entry (the downloaded tar or the extraction staging dir) is only leaked by-# a hard kill (SIGKILL/OOM/power loss — the ``finally`` never runs). Entries embed the owning-# PID and an entry whose owner is dead is reclaimed immediately, whatever its age, so this-# cutoff only governs names without an embedded PID (leftovers from before the ownership-# scheme — no live process still creates them, so a short window suffices) and Windows hosts,-# where an arbitrary PID cannot be probed. The old 6 h window let a crash loop accumulate-# tens of GB before anything was reclaimed (#114437).+# a hard kill (SIGKILL/OOM/power loss — the ``finally`` never runs). Entry names embed the+# owning PID, so a dead owner's entry is reclaimed at once; the age cutoff covers the rest+# (live or recycled PIDs, pre-ownership names, Windows where a PID cannot be probed). The+# download is bounded by a 120 s subprocess timeout, so a live transfer is minutes old at+# most; the old 6 h window let a crash loop pile up tens of GB before anything was reclaimed._SYNC_BACK_STALE_SECONDS = 30 * 60-def _sync_back_temp_prefix() -> str:- """Temp prefix embedding the owning PID, mirroring daytona's PID-suffixed remote temp.+def _sync_back_max_bytes() -> int:+ """Extraction cap; ``HERMES_SYNC_BACK_MAX_BYTES`` overrides it for trees that legitimately+ exceed 2 GiB (a skipped extraction silently discards the whole download)."""+ raw = os.environ.get(_SYNC_BACK_MAX_BYTES_ENV, "").strip()+ if raw:+ try:+ return int(raw)+ except ValueError:+ logger.warning("sync_back: ignoring non-integer %s=%r", _SYNC_BACK_MAX_BYTES_ENV, raw)+ return _SYNC_BACK_MAX_BYTES- Ownership lets the stale sweep reclaim an entry the moment its owner process is gone- (age-independent, and safe between concurrent gateway processes, which hold distinct- PIDs) instead of guessing liveness from mtime — a staging dir's mtime does not move- while content streams into its subdirectories.- """++def _sync_back_temp_prefix() -> str:+ """Temp prefix embedding the owning PID so the stale sweep can tell a hard-killed+ process's leftovers from another live gateway's in-flight transfer without guessing+ from mtime (a staging dir's mtime does not move while content streams into it)."""return f"{_SYNC_BACK_TEMP_PREFIX}{os.getpid()}-"-def _temp_entry_owner_pid(name: str) -> int | None:- """Return the PID embedded in a sync-back temp entry name, or None for legacy names."""- if not name.startswith(_SYNC_BACK_TEMP_PREFIX):- return None+def _temp_entry_owner_alive(name: str) -> bool:+ """Whether the process that created a sync-back temp entry may still be running.+ Names without a PID (and hosts without psutil) count as alive: the age cutoff applies."""pid_part = name[len(_SYNC_BACK_TEMP_PREFIX):].split("-", 1)[0]- return int(pid_part) if pid_part.isdigit() else None---def _pid_alive(pid: int) -> bool:- """Whether *pid* names a live process (POSIX signal-0 probe; callers guard for Windows)."""- try:- os.kill(pid, 0)- except ProcessLookupError:- return False- except PermissionError: # exists but is owned by another user+ if not pid_part.isdigit():return True- except OSError:+ try:+ import psutil+ except ImportError:return True- return True+ return psutil.pid_exists(int(pid_part))def _cleanup_stale_sync_back_temp(temp_dir: Path | None = None) -> int:"""Remove sync-back tars and staging dirs left behind by a hard-killed process.- An entry whose embedded owner PID is no longer alive is reclaimed immediately —- age-independent, and never touching another live process's transfer even though the- file lock is per ``HERMES_HOME`` while the temp directory is shared. Entries without- an embedded PID (pre-ownership leftovers) and Windows hosts fall back to the- ``_SYNC_BACK_STALE_SECONDS`` cutoff. Returns the number of entries removed; a- permission error or a race with another sync-back must not prevent the current one.+ Only entries carrying this module's prefix are touched: at once when their owner PID+ is dead, otherwise only past ``_SYNC_BACK_STALE_SECONDS``. Returns the number of+ entries removed; a permission error or a race with another sync-back must not prevent+ the current one."""directory = temp_dir or Path(tempfile.gettempdir())cutoff = time.time() - _SYNC_BACK_STALE_SECONDS@@ -111,14 +109,10 @@ def _cleanup_stale_sync_back_temp(temp_dir: Path | None = None) -> int:return 0for candidate in candidates:try:- owner = _temp_entry_owner_pid(candidate.name)- if owner is not None and os.name != "nt":- if _pid_alive(owner):- continue # a live process owns this entry — leave it alone- elif candidate.is_symlink() or candidate.lstat().st_mtime >= cutoff:- continueif candidate.is_symlink():continue+ if _temp_entry_owner_alive(candidate.name) and candidate.lstat().st_mtime >= cutoff:+ continueif candidate.is_dir():shutil.rmtree(candidate)else:@@ -407,10 +401,11 @@ class FileSyncManager:tar_size = os.path.getsize(tar_path)except OSError:tar_size = 0- if tar_size > _SYNC_BACK_MAX_BYTES:+ max_bytes = _sync_back_max_bytes()+ if tar_size > max_bytes:logger.warning(- "sync_back: remote tar is %d bytes (cap %d) — skipping extraction",- tar_size, _SYNC_BACK_MAX_BYTES)+ "sync_back: remote tar is %d bytes (cap %d, override with %s) — skipping extraction",+ tar_size, max_bytes, _SYNC_BACK_MAX_BYTES_ENV)returnwith tempfile.TemporaryDirectory(prefix=_sync_back_temp_prefix()) as staging:diff --git a/tools/environments/modal.py b/tools/environments/modal.pyindex cec7f8524f1..d71c1c12ad8 100644--- a/tools/environments/modal.py+++ b/tools/environments/modal.py@@ -234,8 +234,7 @@ class ModalEnvironment(BaseEnvironment):def _modal_bulk_download(self, dest: Path) -> None:"""Download remote .hermes/ as a tar archive (sandboxes run as root, so /root/.hermes)."""- # --exclude: live sockets cannot be archived ("socket ignored"), and a tar build that- # makes the skipped socket fatal would fail the download (#114437).+ # --exclude: live sockets cannot be archived ("socket ignored") and must not fail the download.data = self._exec("tar cf - --exclude='*.sock' -C / root/.hermes", timeout=120, fail_label="bulk download", capture=True)dest.write_bytes(data.encode() if isinstance(data, str) else data)diff --git a/tools/environments/ssh.py b/tools/environments/ssh.pyindex 0e831137602..ff021a08376 100644--- a/tools/environments/ssh.py+++ b/tools/environments/ssh.py@@ -245,19 +245,17 @@ class SSHEnvironment(BaseEnvironment):# (home/user/.hermes/skills/f.py), matching _pushed_hashes keys.rel_base = f"{self._remote_home}/.hermes".lstrip("/")# Live sockets inside .hermes (gateway.sock and friends) cannot be archived: tar prints- # "socket ignored" and exits 2, which used to fail every sync-back and leave a multi-GB- # temp tar behind on each retry (#114437). Exclude them up front.+ # "socket ignored" and some builds exit 2, which failed every sync-back and left a+ # multi-GB temp tar behind on each retry. Exclude them up front.ssh_cmd = self._build_ssh_command() + [f"tar cf - --exclude='*.sock' -C / {shlex.quote(rel_base)}"]with open(dest, "wb") as f:result = subprocess.run(ssh_cmd, stdin=subprocess.DEVNULL, stdout=f, stderr=subprocess.PIPE, timeout=120)if result.returncode != 0:stderr = result.stderr.decode(errors="replace").strip()- # tar exits 2 for non-fatal conditions; a socket that slipped past the exclude- # pattern (or a tar without --exclude support) is the only one we knowingly accept,- # and only when nothing else was reported — anchored to the diagnostic suffix so a- # filename merely containing "socket ignored" cannot sneak through. Every other- # non-zero status still fails the transfer.+ # A socket not named *.sock is the only rc=2 we knowingly accept, and only when+ # nothing else was reported — anchored to the diagnostic suffix so a filename merely+ # containing "socket ignored" cannot sneak through. Every other status still fails.diagnostic_lines = [line for line in stderr.splitlines() if line.strip()]tolerated = result.returncode == 2 and bool(diagnostic_lines) and all(line.endswith(": socket ignored") for line in diagnostic_lines)diff --git a/tools/environments/vercel_sandbox.py b/tools/environments/vercel_sandbox.pyindex 73c88b318bf..06353a186fd 100644--- a/tools/environments/vercel_sandbox.py+++ b/tools/environments/vercel_sandbox.py@@ -291,7 +291,9 @@ class VercelSandboxEnvironment(BaseEnvironment):remote_tar = f"/tmp/.hermes_sync.{os.getpid()}.tar"sandbox = self._require_sandbox()try:- self._run_checked(f"tar cf {shlex.quote(remote_tar)} -C / {shlex.quote(archive_member)}", "bulk download")+ # --exclude: live sockets cannot be archived ("socket ignored") and must not fail the download.+ self._run_checked(f"tar cf {shlex.quote(remote_tar)} --exclude='*.sock' -C / {shlex.quote(archive_member)}",+ "bulk download")sandbox.download_file(remote_tar, dest_tar_path)finally:with contextlib.suppress(Exception):diff --git a/website/docs/user-guide/configuration.md b/website/docs/user-guide/configuration.mdindex 2daec8ce377..3ddd941face 100644--- a/website/docs/user-guide/configuration.md+++ b/website/docs/user-guide/configuration.md@@ -591,7 +591,8 @@ When in doubt, set `terminal.backend` back to `local` and verify that commands rFor the **SSH**, **Modal**, and **Daytona** backends, Hermes pushes your `~/.hermes/` state (credential files, skills, cache) into the remote sandbox during the session, and on teardown **syncs changed state files back** to their original host locations. Files that differ from what was originally pushed (compared by content hash) are applied back in place; new remote files under a synced directory (e.g. a skill the agent created remotely) are mapped back to the corresponding host path. Upload-only credential files are never overwritten on the host.-- The sync-back retries up to 3 times with backoff and refuses to extract remote archives larger than 2 GiB.+- The sync-back retries up to 3 times with backoff and refuses to extract remote archives larger than 2 GiB; set `HERMES_SYNC_BACK_MAX_BYTES` (bytes) to raise the cap for a larger state tree. Live sockets under the remote `~/.hermes/` (e.g. `gateway.sock`) are skipped rather than failing the transfer.+- The downloaded archive is staged under the system temp directory (`hermes-sync-back-<pid>-*`); leftovers from a hard-killed process are reclaimed on the next sync-back.- Docker and Singularity use bind mounts (live host filesystem view) and don't need this.- This covers Hermes state (`~/.hermes/`), **not** arbitrary working-tree files inside the sandbox — have the agent copy important artifacts out explicitly (e.g. `scp`, `modal volume put`) before the sandbox is destroyed.