@@ -64,6 +64,11 @@ def sandbox_path_str(path: str | PurePath) -> str:
6464 return coerce_posix_path (path ).as_posix ()
6565
6666
67+ def _native_path_from_windows_absolute (path : PureWindowsPath ) -> Path | None :
68+ native_path = Path (path )
69+ return native_path if native_path .is_absolute () else None
70+
71+
6772class SandboxPathGrant (BaseModel ):
6873 """Extra absolute path access outside the sandbox workspace."""
6974
@@ -83,16 +88,14 @@ def _coerce_path(cls, value: object) -> str:
8388 @field_validator ("path" )
8489 @classmethod
8590 def _validate_path (cls , value : str ) -> str :
91+ if windows_absolute_path (value ) is not None :
92+ raise ValueError ("sandbox path grant path must be POSIX absolute" )
93+
8694 path = PurePosixPath (posixpath .normpath (value ))
8795 if path .is_absolute ():
8896 _raise_if_filesystem_root (path )
8997 return path .as_posix ()
9098
91- windows_path = PureWindowsPath (value )
92- if windows_path .is_absolute ():
93- _raise_if_filesystem_root (windows_path )
94- return windows_path .as_posix ()
95-
9699 raise ValueError ("sandbox path grant path must be absolute" )
97100
98101
@@ -120,8 +123,9 @@ def absolute_workspace_path(self, path: str | PurePath) -> Path:
120123 """
121124
122125 if (windows_path := windows_absolute_path (path )) is not None :
123- if self ._root_is_existing_host_path :
124- result , _grant = self ._resolved_host_path_and_grant (Path (windows_path ))
126+ native_path = _native_path_from_windows_absolute (windows_path )
127+ if self ._root_is_existing_host_path and native_path is not None :
128+ result , _grant = self ._resolved_host_path_and_grant (native_path )
125129 return result
126130 raise self ._invalid_path_error (windows_path )
127131 normalized = self ._absolute_workspace_posix_path (coerce_posix_path (path ))
@@ -161,12 +165,18 @@ def normalize_path(
161165 """
162166
163167 if resolve_symlinks :
164- original = Path (path )
168+ if (windows_path := windows_absolute_path (path )) is not None :
169+ original = _native_path_from_windows_absolute (windows_path )
170+ if original is None :
171+ raise self ._invalid_path_error (windows_path )
172+ else :
173+ original = Path (path )
165174 result , grant = self ._resolved_host_path_and_grant (original )
166175 else :
167176 if (windows_path := windows_absolute_path (path )) is not None :
168- if self ._root_is_existing_host_path :
169- result , grant = self ._resolved_host_path_and_grant (Path (windows_path ))
177+ native_path = _native_path_from_windows_absolute (windows_path )
178+ if self ._root_is_existing_host_path and native_path is not None :
179+ result , grant = self ._resolved_host_path_and_grant (native_path )
170180 if for_write :
171181 self ._raise_if_read_only_grant (result , grant )
172182 return result
0 commit comments