Uh oh!
There was an error while loading. Please reload this page.
fix(sandbox): make UnixLocal persist_workspace archives restorable by hydrate_workspace - #4831
Open
coderdailyone wants to merge 1 commit into
Open
Conversation
UnixLocalSandboxSession.persist_workspace() archived the workspace
with tarfile.add() unchanged, while hydrate_workspace() extracts with
the strict policy that refuses hardlink members, FIFOs/device nodes and
absolute symlink targets. Ordinary workspaces hit all three: uv and
pnpm hardlink installed packages, dev servers leave FIFOs behind, and
`ln -s "$PWD/file" link` writes an absolute target. The snapshot was
taken successfully and then could never be restored
("hardlink member not allowed", "unsupported member type",
"absolute symlink target not allowed: /tmp/sandbox-local-.../file").
Rewrite members while archiving: store hardlinks as regular files,
drop FIFOs and device nodes, and turn an absolute symlink target that
stays under the workspace root into a relative one so it also survives
the root moving between sessions. Absolute targets outside the
workspace are left unchanged; hydrate keeps rejecting them by design.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BN4v25msJgrjNgac97g1Az
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for freeto join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request fixes
UnixLocalSandboxSession.persist_workspace()so the archive it produces can actually be restored byhydrate_workspace().Bug
persist_workspace()archives the workspace withtarfile.add()as-is, whilehydrate_workspace()extracts with the strict policy (safe_extract_tarfile(..., allow_external_symlink_targets=False)) that refuses hardlink members, FIFOs / device nodes, and absolute symlink targets. Ordinary local workspaces contain all three, so the snapshot is taken successfully and then can never be restored. Reproduced onmainwith a realUnixLocalSandboxClientsession (persist into one session, hydrate into a fresh one):maina.txt+ln a.txt b.txt(whatuv/pnpmdo for every installed package)WorkspaceArchiveWriteError—hardlink member not allowed, member./b.txtmkfifo pipe)unsupported member type, member./pipeln -s "$PWD/a.txt" abs_inside(absolute link to a file inside the workspace)absolute symlink target not allowed: /tmp/sandbox-local-…/a.txtpython3 -m venv .venvabsolute symlink target not allowed: /usr/bin/python3The last row is the intentional #3094 policy and is not changed here. The first three are not "external" in any sense, and the absolute-internal link is additionally wrong after restore even if it were accepted, because UnixLocal creates a fresh
/tmp/sandbox-local-*root per session.Fix
Add a
filterstep to thetarfile.add()call inpersist_workspace()(_restorable_tar_member):TarFile.addthen reads the payload), so the restored workspace has two files with the same content;tarfile);/tmpis itself a symlink) is rewritten to a path relative to the link's own directory, e.g./tmp/sandbox-local-x/a.txtfromsub/abs_upbecomes../a.txt;No public signatures change and
hydrate_workspace()is not modified.Evidence
tests/sandbox/test_unix_local.py::TestUnixLocalPersistWorkspaceRestorableinspects the emitted members and round-trips the archive into a new root throughhydrate_workspace(); both tests fail onmainand pass with this change.tests/sandbox/test_unix_local.py,test_tar_utils.py,test_extract.py,ruff,mypy, andpyrighton the changed files pass locally (Linux, Python 3.10).🤖 Generated with Claude Code
https://claude.ai/code/session_01BN4v25msJgrjNgac97g1Az