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

Commit 3f8496b

Browse files
committed
fix the errors
1 parent b63d43a commit 3f8496b

File tree

22 files changed

+410
-244
lines changed

22 files changed

+410
-244
lines changed

src/agents/extensions/sandbox/blaxel/mounts.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ async def activate(
8181
_assert_blaxel_session(session)
8282
_ = base_dir
8383
mount_path = mount._resolve_mount_path(session, dest)
84-
config = _build_mount_config(mount, mount_path=str(mount_path))
84+
config = _build_mount_config(mount, mount_path=mount_path.as_posix())
8585
await _mount_bucket(session, config)
8686
return []
8787

@@ -95,7 +95,7 @@ async def deactivate(
9595
_assert_blaxel_session(session)
9696
_ = base_dir
9797
mount_path = mount._resolve_mount_path(session, dest)
98-
await _unmount_bucket(session, str(mount_path))
98+
await _unmount_bucket(session, mount_path.as_posix())
9999

100100
async def teardown_for_snapshot(
101101
self,

src/agents/extensions/sandbox/blaxel/sandbox.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
retry_async,
6666
)
6767
from ....sandbox.util.tar_utils import UnsafeTarMemberError, validate_tar_bytes
68+
from ....sandbox.workspace_paths import coerce_posix_path, posix_path_as_path
6869

6970
DEFAULT_BLAXEL_WORKSPACE_ROOT = "/workspace"
7071
logger = logging.getLogger(__name__)
@@ -377,7 +378,7 @@ async def mkdir(
377378
) from e
378379

379380
async def read(self, path: Path | str, *, user: str | User | None = None) -> io.IOBase:
380-
path = Path(path)
381+
path = posix_path_as_path(coerce_posix_path(path))
381382
if user is not None:
382383
workspace_path = await self._check_read_with_exec(path, user=user)
383384
else:
@@ -407,7 +408,7 @@ async def write(
407408
*,
408409
user: str | User | None = None,
409410
) -> None:
410-
path = Path(path)
411+
path = posix_path_as_path(coerce_posix_path(path))
411412
if user is not None:
412413
await self._check_write_with_exec(path, user=user)
413414

@@ -525,11 +526,11 @@ def _tar_exclude_args(self) -> list[str]:
525526
)
526527
)
527528
async def persist_workspace(self) -> io.IOBase:
528-
root = Path(self.state.manifest.root)
529+
root = self._workspace_root_path()
529530
tar_path = f"/tmp/bl-persist-{self.state.session_id.hex}.tar"
530531
excludes = " ".join(self._tar_exclude_args())
531532
tar_cmd = (
532-
f"tar {excludes} -C {shlex.quote(str(root))} -cf {shlex.quote(tar_path)} ."
533+
f"tar {excludes} -C {shlex.quote(root.as_posix())} -cf {shlex.quote(tar_path)} ."
533534
).strip()
534535

535536
unmounted_mounts: list[tuple[Mount, Path]] = []
@@ -596,7 +597,7 @@ async def persist_workspace(self) -> io.IOBase:
596597
return io.BytesIO(raw)
597598

598599
async def hydrate_workspace(self, data: io.IOBase) -> None:
599-
root = self.state.manifest.root
600+
root = self._workspace_root_path()
600601
tar_path = f"/tmp/bl-hydrate-{self.state.session_id.hex}.tar"
601602
payload = data.read()
602603
if isinstance(payload, str):
@@ -608,7 +609,7 @@ async def hydrate_workspace(self, data: io.IOBase) -> None:
608609
validate_tar_bytes(bytes(payload))
609610
except UnsafeTarMemberError as e:
610611
raise WorkspaceArchiveWriteError(
611-
path=Path(root),
612+
path=root,
612613
context={
613614
"reason": "unsafe_or_invalid_tar",
614615
"member": e.member,
@@ -623,12 +624,12 @@ async def hydrate_workspace(self, data: io.IOBase) -> None:
623624
result = await self._exec_internal(
624625
"sh",
625626
"-c",
626-
f"tar -C {shlex.quote(root)} -xf {shlex.quote(tar_path)}",
627+
f"tar -C {shlex.quote(root.as_posix())} -xf {shlex.quote(tar_path)}",
627628
timeout=self.state.timeouts.workspace_tar_s,
628629
)
629630
if result.exit_code != 0:
630631
raise WorkspaceArchiveWriteError(
631-
path=Path(root),
632+
path=root,
632633
context={
633634
"reason": "tar_extract_failed",
634635
"output": result.stderr.decode("utf-8", errors="replace"),
@@ -637,7 +638,7 @@ async def hydrate_workspace(self, data: io.IOBase) -> None:
637638
except WorkspaceArchiveWriteError:
638639
raise
639640
except Exception as e:
640-
raise WorkspaceArchiveWriteError(path=Path(root), cause=e) from e
641+
raise WorkspaceArchiveWriteError(path=root, cause=e) from e
641642
finally:
642643
try:
643644
await self._exec_internal(

src/agents/extensions/sandbox/cloudflare/sandbox.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
retry_async,
6868
)
6969
from ....sandbox.util.tar_utils import UnsafeTarMemberError, validate_tar_bytes
70+
from ....sandbox.workspace_paths import coerce_posix_path, posix_path_as_path
7071

7172
_DEFAULT_EXEC_TIMEOUT_S = 30.0
7273
_DEFAULT_REQUEST_TIMEOUT_S = 120.0
@@ -345,7 +346,9 @@ async def mount_bucket(
345346
mount_path: Path | str,
346347
options: dict[str, object],
347348
) -> None:
348-
workspace_path = await self._validate_path_access(mount_path, for_write=True)
349+
workspace_path = await self._validate_path_access(
350+
coerce_posix_path(mount_path).as_posix(), for_write=True
351+
)
349352
http = self._session()
350353
url = self._url("mount")
351354
payload = {
@@ -389,7 +392,9 @@ async def mount_bucket(
389392
) from e
390393

391394
async def unmount_bucket(self, mount_path: Path | str) -> None:
392-
workspace_path = await self._validate_path_access(mount_path, for_write=True)
395+
workspace_path = await self._validate_path_access(
396+
coerce_posix_path(mount_path).as_posix(), for_write=True
397+
)
393398
http = self._session()
394399
url = self._url("unmount")
395400
payload = {"mountPath": str(workspace_path)}
@@ -501,10 +506,10 @@ def _handle_event_payload(data: str) -> None:
501506

502507
async def _prepare_backend_workspace(self) -> None:
503508
try:
504-
root = Path(self.state.manifest.root)
505-
await self._exec_internal("mkdir", "-p", "--", str(root))
509+
root = self._workspace_root_path()
510+
await self._exec_internal("mkdir", "-p", "--", root.as_posix())
506511
except Exception as e:
507-
raise WorkspaceStartError(path=Path(self.state.manifest.root), cause=e) from e
512+
raise WorkspaceStartError(path=self._workspace_root_path(), cause=e) from e
508513

509514
async def _can_reuse_restorable_snapshot_workspace(self) -> bool:
510515
if not self._workspace_state_preserved_on_start():
@@ -518,7 +523,7 @@ async def _can_reuse_restorable_snapshot_workspace(self) -> bool:
518523
return await self._can_skip_snapshot_restore_on_resume(is_running=is_running)
519524

520525
async def _restore_snapshot_into_workspace_on_resume(self) -> None:
521-
root = Path(self.state.manifest.root)
526+
root = self._workspace_root_path()
522527
detached_mounts: list[tuple[Any, Path]] = []
523528
if self._restore_workspace_was_running:
524529
for mount_entry, mount_path in self.state.manifest.ephemeral_mount_targets():
@@ -965,7 +970,7 @@ async def pty_terminate_all(self) -> None:
965970
await self._terminate_pty_entry(entry)
966971

967972
async def read(self, path: Path | str, *, user: str | User | None = None) -> io.IOBase:
968-
path = Path(path)
973+
path = posix_path_as_path(coerce_posix_path(path))
969974
if user is not None:
970975
await self._check_read_with_exec(path, user=user)
971976

@@ -1029,7 +1034,7 @@ async def write(
10291034
*,
10301035
user: str | User | None = None,
10311036
) -> None:
1032-
path = Path(path)
1037+
path = posix_path_as_path(coerce_posix_path(path))
10331038
if user is not None:
10341039
await self._check_write_with_exec(path, user=user)
10351040

@@ -1106,7 +1111,7 @@ async def running(self) -> bool:
11061111
or _is_transient_workspace_error(exc)
11071112
)
11081113
async def _persist_workspace_via_http(self) -> io.IOBase:
1109-
root = Path(self.state.manifest.root)
1114+
root = self._workspace_root_path()
11101115
skip = self._persist_workspace_skip_relpaths()
11111116
excludes_param = ",".join(
11121117
rel.as_posix().removeprefix("./")
@@ -1148,7 +1153,7 @@ async def _persist_workspace_via_http(self) -> io.IOBase:
11481153
or _is_transient_workspace_error(exc)
11491154
)
11501155
async def _hydrate_workspace_via_http(self, data: io.IOBase) -> None:
1151-
root = Path(self.state.manifest.root)
1156+
root = self._workspace_root_path()
11521157
raw = data.read()
11531158
if isinstance(raw, str):
11541159
raw = raw.encode("utf-8")
@@ -1199,7 +1204,7 @@ async def _hydrate_workspace_via_http(self, data: io.IOBase) -> None:
11991204
raise WorkspaceArchiveWriteError(path=root, cause=e) from e
12001205

12011206
async def persist_workspace(self) -> io.IOBase:
1202-
root = Path(self.state.manifest.root)
1207+
root = self._workspace_root_path()
12031208
unmounted_mounts: list[tuple[Any, Path]] = []
12041209
unmount_error: WorkspaceArchiveReadError | None = None
12051210
for mount_entry, mount_path in self.state.manifest.ephemeral_mount_targets():
@@ -1245,7 +1250,7 @@ async def persist_workspace(self) -> io.IOBase:
12451250
return persisted
12461251

12471252
async def hydrate_workspace(self, data: io.IOBase) -> None:
1248-
root = Path(self.state.manifest.root)
1253+
root = self._workspace_root_path()
12491254
unmounted_mounts: list[tuple[Any, Path]] = []
12501255
unmount_error: WorkspaceArchiveWriteError | None = None
12511256
for mount_entry, mount_path in self.state.manifest.ephemeral_mount_targets():

src/agents/extensions/sandbox/daytona/sandbox.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
retry_async,
6464
)
6565
from ....sandbox.util.tar_utils import UnsafeTarMemberError, validate_tar_bytes
66+
from ....sandbox.workspace_paths import coerce_posix_path, posix_path_as_path
6667

6768
DEFAULT_DAYTONA_WORKSPACE_ROOT = "/home/daytona/workspace"
6869
logger = logging.getLogger(__name__)
@@ -782,7 +783,7 @@ async def _terminate_pty_entry(self, entry: _DaytonaPtySessionEntry) -> None:
782783
pass
783784

784785
async def read(self, path: Path | str, *, user: str | User | None = None) -> io.IOBase:
785-
path = Path(path)
786+
path = posix_path_as_path(coerce_posix_path(path))
786787
if user is not None:
787788
workspace_path = await self._check_read_with_exec(path, user=user)
788789
else:
@@ -809,7 +810,7 @@ async def write(
809810
*,
810811
user: str | User | None = None,
811812
) -> None:
812-
path = Path(path)
813+
path = posix_path_as_path(coerce_posix_path(path))
813814
if user is not None:
814815
await self._check_write_with_exec(path, user=user)
815816

@@ -859,7 +860,6 @@ def _tar_exclude_args(self) -> list[str]:
859860
)
860861
)
861862
async def _run_persist_workspace_command(self, tar_cmd: str, tar_path: str) -> bytes:
862-
root = self.state.manifest.root
863863
try:
864864
envs = await self._resolved_envs()
865865
result = await self._sandbox.process.exec(
@@ -869,7 +869,7 @@ async def _run_persist_workspace_command(self, tar_cmd: str, tar_path: str) -> b
869869
)
870870
if result.exit_code != 0:
871871
raise WorkspaceArchiveReadError(
872-
path=Path(root),
872+
path=self._workspace_root_path(),
873873
context={"reason": "tar_failed", "output": result.result or ""},
874874
)
875875
return cast(
@@ -882,7 +882,7 @@ async def _run_persist_workspace_command(self, tar_cmd: str, tar_path: str) -> b
882882
except WorkspaceArchiveReadError:
883883
raise
884884
except Exception as e:
885-
raise WorkspaceArchiveReadError(path=Path(root), cause=e) from e
885+
raise WorkspaceArchiveReadError(path=self._workspace_root_path(), cause=e) from e
886886

887887
async def persist_workspace(self) -> io.IOBase:
888888
def _error_context_summary(error: WorkspaceArchiveReadError) -> dict[str, str]:
@@ -892,11 +892,11 @@ def _error_context_summary(error: WorkspaceArchiveReadError) -> dict[str, str]:
892892
summary["cause"] = str(error.cause)
893893
return summary
894894

895-
root = Path(self.state.manifest.root)
895+
root = self._workspace_root_path()
896896
tar_path = f"/tmp/sandbox-persist-{self.state.session_id.hex}.tar"
897897
excludes = " ".join(self._tar_exclude_args())
898898
tar_cmd = (
899-
f"tar {excludes} -C {shlex.quote(str(root))} -cf {shlex.quote(tar_path)} ."
899+
f"tar {excludes} -C {shlex.quote(root.as_posix())} -cf {shlex.quote(tar_path)} ."
900900
).strip()
901901

902902
unmounted_mounts: list[tuple[Mount, Path]] = []
@@ -964,7 +964,7 @@ def _error_context_summary(error: WorkspaceArchiveReadError) -> dict[str, str]:
964964
return io.BytesIO(raw)
965965

966966
async def hydrate_workspace(self, data: io.IOBase) -> None:
967-
root = self.state.manifest.root
967+
root = self._workspace_root_path()
968968
tar_path = f"/tmp/sandbox-hydrate-{self.state.session_id.hex}.tar"
969969
payload = data.read()
970970
if isinstance(payload, str):
@@ -976,7 +976,7 @@ async def hydrate_workspace(self, data: io.IOBase) -> None:
976976
validate_tar_bytes(bytes(payload))
977977
except UnsafeTarMemberError as e:
978978
raise WorkspaceArchiveWriteError(
979-
path=Path(root),
979+
path=root,
980980
context={
981981
"reason": "unsafe_or_invalid_tar",
982982
"member": e.member,
@@ -994,19 +994,19 @@ async def hydrate_workspace(self, data: io.IOBase) -> None:
994994
timeout=self.state.timeouts.file_upload_s,
995995
)
996996
result = await self._sandbox.process.exec(
997-
f"tar -C {shlex.quote(root)} -xf {shlex.quote(tar_path)}",
997+
f"tar -C {shlex.quote(root.as_posix())} -xf {shlex.quote(tar_path)}",
998998
env=envs or None,
999999
timeout=self.state.timeouts.workspace_tar_s,
10001000
)
10011001
if result.exit_code != 0:
10021002
raise WorkspaceArchiveWriteError(
1003-
path=Path(root),
1003+
path=root,
10041004
context={"reason": "tar_extract_failed", "output": result.result or ""},
10051005
)
10061006
except WorkspaceArchiveWriteError:
10071007
raise
10081008
except Exception as e:
1009-
raise WorkspaceArchiveWriteError(path=Path(root), cause=e) from e
1009+
raise WorkspaceArchiveWriteError(path=root, cause=e) from e
10101010
finally:
10111011
try:
10121012
envs = await self._resolved_envs()

0 commit comments

Comments
 (0)