Skip to content

The agent that grows with you

fix(terminal): every Windows drive letter is a host cwd, not just C: (#60962)

kshitijk4poorbb504a2e14c3
diff --git a/tests/tools/test_modal_sandbox_fixes.py b/tests/tools/test_modal_sandbox_fixes.py
index 9baed6aa632..ab0be172878 100644
--- a/tests/tools/test_modal_sandbox_fixes.py
+++ b/tests/tools/test_modal_sandbox_fixes.py
@@ -317,22 +317,26 @@ class TestHostPrefixList:
refactor that moves the constant.
"""
- def test_all_common_host_prefixes_present_in_constant(self):
- """The shared prefix constant must list the common host-only roots."""
- for prefix in ("/Users/", "/home/", "C:\\", "C:/"):
- assert prefix in _tt_mod._HOST_CWD_PREFIXES, (
- f"Host prefix {prefix!r} missing from _HOST_CWD_PREFIXES. "
- "Container backends need this to avoid using host paths."
- )
-
def test_all_common_host_paths_flagged_unusable(self):
- """A host path under each prefix must be rejected as a container cwd."""
- for host_path in ("/Users/me/proj", "/home/me/proj",
- "C:\\Users\\me", "C:/Users/me"):
+ """A host path under each user root must be rejected as a container cwd; in-sandbox
+ absolute paths pass."""
+ for host_path in ("/Users/me/proj", "/home/me/proj", "C:\\Users\\me", "C:/Users/me"):
assert _tt_mod._is_unusable_container_cwd(host_path) is True, (
f"Host path {host_path!r} should be rejected as a container "
"cwd but was accepted."
)
+ for sandbox_path in ("/workspace", "/root/proj", "/srv/app"):
+ assert _tt_mod._is_unusable_container_cwd(sandbox_path) is False
+
+ def test_any_windows_drive_letter_is_a_host_cwd(self):
+ """The host-shape predicate is platform-independent data: every drive letter, either slash,
+ is a host path (#60962). On POSIX ``D:\\proj`` is also non-absolute so the container guard
+ already rejected it; on a Windows host it IS absolute and only this predicate catches it."""
+ from tools.terminal_tool_config import _is_host_cwd
+ for host_path in ("C:\\Users\\me", "D:\\proj", "e:/work", "Z:\\"):
+ assert _is_host_cwd(host_path) is True, host_path
+ for not_host in ("/workspace", "/srv/app", "relative/dir", "C", "C:"):
+ assert _is_host_cwd(not_host) is False, not_host
# =========================================================================
diff --git a/tools/terminal_tool.py b/tools/terminal_tool.py
index c5e84198223..65f5e7b9089 100644
--- a/tools/terminal_tool.py
+++ b/tools/terminal_tool.py
@@ -43,7 +43,7 @@ from tools.terminal_tool_lifecycle import (
_evict_environment_for_task, cleanup_all_environments, ensure_task_env,
)
from tools.terminal_tool_config import (
- _HOST_CWD_PREFIXES, _is_container_backend, _is_unusable_container_cwd, _parse_env_var,
+ _is_container_backend, _is_host_cwd, _is_unusable_container_cwd, _parse_env_var,
_plugin_env_flag, _quiet, _safe_getcwd, _tenv, _tenv_bool,
)
from tools.terminal_tool_backends import (
@@ -580,7 +580,7 @@ def _resolve_config_cwd(env_type: str, mount_docker_cwd: bool) -> tuple:
if env_type == "docker" and mount_docker_cwd:
candidate = os.path.abspath(os.path.expanduser(_tenv("TERMINAL_CWD") or _safe_getcwd()))
if (
- any(candidate.startswith(p) for p in _HOST_CWD_PREFIXES)
+ _is_host_cwd(candidate)
or (os.path.isabs(candidate) and os.path.isdir(candidate) and not candidate.startswith(("/workspace", "/root")))
):
host_cwd = candidate
diff --git a/tools/terminal_tool_config.py b/tools/terminal_tool_config.py
index b1643f7f0fd..9bb017040d6 100644
--- a/tools/terminal_tool_config.py
+++ b/tools/terminal_tool_config.py
@@ -9,6 +9,7 @@ so ``tools.terminal_tool.<name>`` keeps resolving (and monkeypatching) as before
import logging
import json
import os
+import re
from contextlib import contextmanager
from typing import Any
@@ -51,9 +52,14 @@ def _safe_getcwd() -> str:
return _tenv("TERMINAL_CWD") or os.path.expanduser("~")
-# Host-cwd prefixes that cannot exist inside a container sandbox (POSIX user
-# dirs and Windows drive paths as they leak toward a Linux ``-w`` flag).
-_HOST_CWD_PREFIXES = ("/Users/", "/home/", "C:\\", "C:/")
+# Host-cwd shapes that cannot exist inside a container sandbox: POSIX user dirs and ANY Windows
+# drive path (``D:\\...``, ``e:/...``) as they leak toward a Linux ``-w`` flag.
+_HOST_CWD_PREFIXES = ("/Users/", "/home/")
+_WINDOWS_DRIVE_RE = re.compile(r"^[A-Za-z]:[\\/]")
+
+
+def _is_host_cwd(path: str) -> bool:
+ return path.startswith(_HOST_CWD_PREFIXES) or bool(_WINDOWS_DRIVE_RE.match(path))
_CONTAINER_BACKENDS = frozenset({"docker", "singularity", "modal", "daytona", "vercel_sandbox"})
_BUILTIN_BACKENDS = _CONTAINER_BACKENDS | {"local", "ssh", "managed_modal"}
@@ -94,7 +100,7 @@ def _is_unusable_container_cwd(cwd: str) -> bool:
workdir: ``docker run -w`` needs an absolute in-sandbox path, otherwise the
container fails to start (exit 125). Windows drive paths aren't ``isabs``
on POSIX, so they're caught by the prefix check."""
- return bool(cwd) and (cwd.startswith(_HOST_CWD_PREFIXES) or not os.path.isabs(cwd))
+ return bool(cwd) and (_is_host_cwd(cwd) or not os.path.isabs(cwd))
def _tenv(name: str, default: str = "") -> str: