豆豆友情提示:这是一个非官方 GitHub 代理镜像,主要用于网络测试或访问加速。请勿在此进行登录、注册或处理任何敏感信息。进行这些操作请务必访问官方网站 github.com。 Raw 内容也通过此代理提供。
Skip to content

Commit 8ab3167

Browse files
committed
fix errors
1 parent 3f8496b commit 8ab3167

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/agents/sandbox/workspace_paths.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def __init__(
8383
) -> None:
8484
self._root = Path(root)
8585
self._sandbox_root = coerce_posix_path(root)
86-
self._root_is_existing_host_path = self._root.exists()
86+
self._root_is_existing_host_path = self._path_exists(self._root)
8787
self._extra_path_grants = extra_path_grants
8888

8989
def absolute_workspace_path(self, path: str | PurePath) -> Path:
@@ -237,6 +237,13 @@ def _absolute_posix_path(self, path: PurePosixPath) -> PurePosixPath:
237237
def _normalized_root(self) -> PurePosixPath:
238238
return PurePosixPath(posixpath.normpath(self._sandbox_root.as_posix()))
239239

240+
@staticmethod
241+
def _path_exists(path: Path) -> bool:
242+
try:
243+
return path.exists()
244+
except OSError:
245+
return False
246+
240247
def _path_result(self, path: PurePosixPath) -> Path:
241248
if self._root_is_existing_host_path:
242249
return Path(path.as_posix())

tests/sandbox/test_workspace_paths.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,22 @@ def test_normalize_path_uses_posix_paths_for_windows_inputs() -> None:
251251
)
252252

253253

254+
def test_inaccessible_root_is_treated_as_remote_path(monkeypatch: pytest.MonkeyPatch) -> None:
255+
root = PurePosixPath("/root/project")
256+
257+
def raise_for_root(path: Path) -> bool:
258+
if path.as_posix() == root.as_posix():
259+
raise PermissionError("permission denied")
260+
return False
261+
262+
monkeypatch.setattr(Path, "exists", raise_for_root)
263+
264+
policy = WorkspacePathPolicy(root=root)
265+
266+
assert policy.root_is_existing_host_path() is False
267+
assert policy.normalize_path("pkg/file.py").as_posix() == "/root/project/pkg/file.py"
268+
269+
254270
def test_absolute_workspace_path_rejects_windows_rooted_escape_as_absolute() -> None:
255271
policy = WorkspacePathPolicy(root="/workspace")
256272

0 commit comments

Comments
 (0)