Skip to content

Commit aa7ed53

Browse files
committed
fix
1 parent 68ee1e5 commit aa7ed53

2 files changed

Lines changed: 36 additions & 2 deletions

File tree

src/agents/sandbox/workspace_paths.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,11 @@ def _coerce_path(cls, value: object) -> str:
8888
@field_validator("path")
8989
@classmethod
9090
def _validate_path(cls, value: str) -> str:
91-
if windows_absolute_path(value) is not None:
91+
if (windows_path := windows_absolute_path(value)) is not None:
92+
native_path = _native_path_from_windows_absolute(windows_path)
93+
if native_path is not None:
94+
_raise_if_filesystem_root(native_path)
95+
return str(native_path)
9296
raise ValueError("sandbox path grant path must be POSIX absolute")
9397

9498
path = PurePosixPath(posixpath.normpath(value))
@@ -268,6 +272,8 @@ def extra_path_grant_rules(self) -> tuple[tuple[PurePosixPath, bool], ...]:
268272

269273
rules: list[tuple[PurePosixPath, bool]] = []
270274
for grant in self._extra_path_grants:
275+
if windows_absolute_path(grant.path) is not None:
276+
raise ValueError("sandbox path grant path must be POSIX absolute")
271277
root = coerce_posix_path(grant.path)
272278
_raise_if_filesystem_root(root)
273279
rules.append((root, grant.read_only))

tests/sandbox/test_workspace_paths.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,10 @@ def test_sandbox_extra_path_grant_rules_use_posix_paths() -> None:
364364
)
365365

366366

367-
def test_extra_path_grant_rejects_windows_drive_absolute_path() -> None:
367+
def test_extra_path_grant_rejects_non_native_windows_drive_absolute_path() -> None:
368+
if Path(PureWindowsPath("C:/tmp")).is_absolute():
369+
pytest.skip("Windows drive paths are native absolute paths on this host")
370+
368371
for path in (
369372
PureWindowsPath("C:/tmp"),
370373
"C:\\tmp",
@@ -387,6 +390,31 @@ def test_extra_path_grant_rejects_windows_drive_absolute_path() -> None:
387390
}
388391

389392

393+
def test_extra_path_grant_accepts_native_windows_drive_absolute_path(
394+
tmp_path: Path,
395+
) -> None:
396+
if not Path(PureWindowsPath("C:/tmp")).is_absolute():
397+
pytest.skip("Windows drive paths are not native absolute paths on this host")
398+
399+
grant = SandboxPathGrant(path=str(tmp_path))
400+
401+
assert Path(grant.path).is_absolute()
402+
403+
404+
def test_extra_path_grant_rules_reject_windows_drive_absolute_path() -> None:
405+
grant = SandboxPathGrant.model_construct(
406+
path="C:/tmp",
407+
read_only=False,
408+
description=None,
409+
)
410+
policy = WorkspacePathPolicy(root="/workspace", extra_path_grants=(grant,))
411+
412+
with pytest.raises(ValueError) as exc_info:
413+
policy.extra_path_grant_rules()
414+
415+
assert str(exc_info.value) == "sandbox path grant path must be POSIX absolute"
416+
417+
390418
def test_manifest_serializes_extra_path_grants() -> None:
391419
manifest = Manifest(
392420
extra_path_grants=(

0 commit comments

Comments
 (0)