utils.sandbox
copy_dir
Copy a directory in the local filesystem, using a tar round-trip for consistent behaviour with copy_dir_to_sandbox and copy_dir_from_sandbox.
def copy_dir(
source_path: Path,
destination_path: Path,
exclude: list[str] | None = None,
include: list[str] | None = None,
) -> Nonesource_pathPath-
The source directory.
destination_pathPath-
The destination directory.
excludelist[str] | None-
Patterns to exclude when copying. If None, nothing is excluded.
includelist[str] | None-
Patterns to include when copying (these override the exclude patterns). If None, no additional includes are added.
copy_dir_from_sandbox
Copy a directory from the sandbox environment to the local filesystem.
async def copy_dir_from_sandbox(
src: Path,
dst: Path,
exclude: list[str] | None = None,
include: list[str] | None = None,
) -> NonesrcPath-
The source directory in the sandbox.
dstPath-
The destination directory on the local filesystem.
excludelist[str] | None-
Patterns to exclude when copying. If None, nothing is excluded.
includelist[str] | None-
Patterns to include when copying (these override the exclude patterns). If None, no additional includes are added.
copy_dir_in_sandbox
Copy a directory from one location to another within the sandbox environment.
This function efficiently copies directories within the sandbox using tar, which preserves file permissions and handles large directories well. The copy operation can exclude specified patterns and optionally change the ownership of the copied files.
async def copy_dir_in_sandbox(
source_path: str | Path,
destination_path: str | Path,
exclude: Sequence[str] | None = None,
include: Sequence[str] | None = None,
owner: str | None = None,
user: str = "root",
) -> ExecResult[str]source_pathstr | Path-
The source directory path within the sandbox to copy from.
destination_pathstr | Path-
The destination directory path within the sandbox to copy to.
excludeSequence[str] | None-
List of patterns to exclude when copying. Patterns are passed to tar’s –exclude flag. If None, no files are excluded.
includeSequence[str] | None-
List of patterns to include when copying. Excludes are applied after includes. If None, defaults to all files.
ownerstr | None-
The owner to set for the copied files (format: “user:group” or just “user”). If None, ownership is not changed.
userstr-
The user to run the copy command as. Defaults to “root” to ensure permissions are handled correctly.
Raises
OSError: If the copy operation fails.
copy_dir_to_sandbox
Copy a directory from the local filesystem to the sandbox environment.
async def copy_dir_to_sandbox(
src: Path,
dst: Path,
exclude: list[str] | None = None,
include: list[str] | None = None,
) -> NonesrcPath-
The source directory on the local filesystem.
dstPath-
The destination directory in the sandbox.
excludelist[str] | None-
Patterns to exclude when copying. If None, nothing is excluded.
includelist[str] | None-
Patterns to include when copying (these override the exclude patterns). If None, no additional includes are added.
copy_location_to_sandbox
Copy the repository at the given location to the sandbox environment. The location can be a local path, a sandbox path, a metadata path, or a snapshot path.
Note: If a sandbox or snapshot location is provided, the location directory will first be copied to a local temporary directory before being copied to the sandbox environment. However, this is an implementation detail that may change in the future.
async def copy_location_to_sandbox(
state: TaskState,
source_location: RepoLocation | Sequence[RepoLocation],
destination_path: str | Path,
exclude: list[str] | None = None,
include: list[str] | None = None,
) -> NonestateTaskState-
TaskState containing the task state
source_locationRepoLocation | Sequence[RepoLocation]-
The location of the repository to copy to the sandbox
destination_pathstr | Path-
The path in the sandbox environment to copy the repository to`
excludelist[str] | None-
List of patterns to exclude when copying over. If None, defaults to excluding nothing.
includelist[str] | None-
List of patterns to include when copying over (these override the exclude args). If None, defaults to no additional includes.
file_exists_in_sandbox
Check if a file exists in the sandbox environment.
async def file_exists_in_sandbox(file_path: str, cwd: str = "/workspace") -> boolfile_pathstr-
Path to the file to check (relative to cwd)
cwdstr-
Working directory in the sandbox (default: /workspace)
Returns
True if the file exists in the sandbox, False otherwise
Raises
Exception: If the existence check cannot be executed in the sandbox. A sandbox failure must not be mistaken for the file not existing, since some callers may use this check to decide which code path to take.
get_diff_from_ref_dir
Get the diff between the agent’s working directory and the reference directory.
For a git repository, the exclude/include arguments filter files before the agent’s changes but not after, so an exclusion can be used to remove a file the agent should write and still show the agent writing it. Paths in the gitignore are ignored on both sides. For a non-git reference, the exclude/include arguments behave roughly like gitignore entries.
async def get_diff_from_ref_dir(
ref_dir: Path,
agent_wd: Path = Path("/repo"),
exclude: list[str] | None = None,
include: list[str] | None = None,
) -> strref_dirPath-
The path to the reference directory.
agent_wdPath-
The path to the agent’s working directory in the sandbox.
excludelist[str] | None-
Patterns to exclude when copying files. If None, nothing is excluded.
includelist[str] | None-
Patterns to include when copying files. If None, no additional includes are added.
Returns
The git diff between the agent’s working directory and the reference directory.