diff --git a/src/agents/sandbox/fs-bridge-mutation-helper.ts b/src/agents/sandbox/fs-bridge-mutation-helper.ts index 39372dfd586..19beb8bad26 100644 --- a/src/agents/sandbox/fs-bridge-mutation-helper.ts +++ b/src/agents/sandbox/fs-bridge-mutation-helper.ts @@ -146,6 +146,14 @@ export const SANDBOX_PINNED_MUTATION_PYTHON = [ " try:", " for child in os.listdir(src_dir_fd):", " move_entry(src_dir_fd, child, temp_dir_fd, child)", + " except Exception:", + " # Rollback: move children from temp_dir back to source to preserve original tree.", + " # Without this, a size-check failure on a later child leaves earlier children stranded", + " # in the hidden temp dir and the source partially deleted.", + " for child in os.listdir(temp_dir_fd):", + " move_entry(temp_dir_fd, child, src_dir_fd, child)", + " remove_tree(dst_parent_fd, temp_dir_name)", + " raise", " finally:", " os.close(src_dir_fd)", " os.close(temp_dir_fd)",