diff --git a/src/agents/sandbox/entries/mounts/patterns.py b/src/agents/sandbox/entries/mounts/patterns.py index e9f6a3751a..c823fc0605 100644 --- a/src/agents/sandbox/entries/mounts/patterns.py +++ b/src/agents/sandbox/entries/mounts/patterns.py @@ -739,6 +739,7 @@ async def _start_rclone_server( *, config: RcloneMountConfig, config_path: Path, + remote_name: str, nfs_addr: str, ) -> None: nfs_check = await session.exec( @@ -753,7 +754,7 @@ async def _start_rclone_server( tool="rclone serve nfs", context={"type": config.mount_type}, ) - cmd: list[str] = ["rclone", "serve", "nfs", f"{config.remote_name}:{config.remote_path}"] + cmd: list[str] = ["rclone", "serve", "nfs", f"{remote_name}:{config.remote_path}"] cmd.extend(["--addr", nfs_addr]) cmd.extend(["--config", sandbox_path_str(config_path)]) if config.read_only: @@ -778,13 +779,14 @@ async def _start_rclone_client( path: Path, config: RcloneMountConfig, config_path: Path, + remote_name: str, nfs_addr: str | None = None, ) -> None: if self.mode == "fuse": cmd: list[str] = [ "rclone", "mount", - f"{config.remote_name}:{config.remote_path}", + f"{remote_name}:{config.remote_path}", sandbox_path_str(path), ] if config.read_only: @@ -900,12 +902,13 @@ async def apply( context={"type": rclone_config.mount_type}, ) session_id_str = session_id.hex + remote_name = rclone_config.remote_name # Keep generated rclone config under the workspace root so `session.mkdir()` / # `session.write()` can handle it without special-casing absolute paths. config_dir = posix_path_as_path( coerce_posix_path(f".sandbox-rclone-config/{session_id_str}") ) - config_path = config_dir / f"{rclone_config.remote_name}.conf" + config_path = config_dir / f"{remote_name}.conf" await session.mkdir(path, parents=True) await session.mkdir(config_dir, parents=True) session.register_persist_workspace_skip_path(config_dir) @@ -924,6 +927,7 @@ async def apply( session, config=rclone_config, config_path=command_config_path, + remote_name=remote_name, nfs_addr=nfs_addr, ) await self._start_rclone_client( @@ -931,6 +935,7 @@ async def apply( path=path, config=rclone_config, config_path=command_config_path, + remote_name=remote_name, nfs_addr=nfs_addr, ) else: @@ -940,6 +945,7 @@ async def apply( path=path, config=rclone_config, config_path=command_config_path, + remote_name=remote_name, ) async def unapply( @@ -965,12 +971,22 @@ async def unapply( shell=False, ) + session_id = getattr(session.state, "session_id", None) + if session_id is None: + remote_name = rclone_config.remote_name + else: + remote_name = self.resolve_remote_name( + session_id=session_id.hex, + remote_kind=rclone_config.remote_kind, + mount_type=rclone_config.mount_type, + ) + await session.exec( "sh", "-lc", ( "pkill -f -- " - f"'rclone (mount|serve nfs) {rclone_config.remote_name}:' >/dev/null 2>&1 || true" + f"'rclone (mount|serve nfs) {remote_name}:' >/dev/null 2>&1 || true" ), shell=False, )