Skip to content

The agent that grows with you

fix(terminal): gate sudo probes by backend cancellation safety

fangliquanflq39abca492d71
diff --git a/tests/tools/test_base_environment.py b/tests/tools/test_base_environment.py
index 9939a0f7474..c0003912519 100644
--- a/tests/tools/test_base_environment.py
+++ b/tests/tools/test_base_environment.py
@@ -14,6 +14,8 @@ from tools.environments.base_output import _BoundedOutputCollector
class _TestableEnv(BaseEnvironment):
"""Concrete subclass for testing base class methods."""
+ _sudo_nopasswd_probe_supported = True
+
def __init__(self, cwd="/tmp", timeout=10):
super().__init__(cwd=cwd, timeout=timeout)
@@ -66,6 +68,16 @@ def test_nopasswd_probe_fails_closed_on_backend_error(monkeypatch):
assert env._sudo_nopasswd_works() is False
+def test_nopasswd_probe_skips_backends_without_safe_process_cancel(monkeypatch):
+ env = _TestableEnv()
+ env._sudo_nopasswd_probe_supported = False
+ run = MagicMock(side_effect=AssertionError("probe must not start"))
+ monkeypatch.setattr(env, "_run_bash", run)
+
+ assert env._sudo_nopasswd_works() is False
+ run.assert_not_called()
+
+
class TestBoundedOutputCollector:
def test_large_stream_retains_bounded_head_and_tail(self):
collector = _BoundedOutputCollector(1_000)
diff --git a/tools/environments/base.py b/tools/environments/base.py
index 8c4d15f6dc4..4bda4793aca 100644
--- a/tools/environments/base.py
+++ b/tools/environments/base.py
@@ -154,6 +154,10 @@ class BaseEnvironment(ABC):
# Snapshot creation timeout (override for slow cold-starts).
_snapshot_timeout: int = 30
+ # Opt in only when a timed-out probe can kill its command without tearing
+ # down the whole backend. SDK adapters cancel by stopping the sandbox.
+ _sudo_nopasswd_probe_supported: bool = False
+
# Local and Docker override this because they resolve allowlisted values
# through the active profile scope; other backends keep plain snapshots.
_profile_scoped_passthrough: bool = False
@@ -597,6 +601,8 @@ class BaseEnvironment(ABC):
def _sudo_nopasswd_works(self) -> bool:
"""Probe passwordless sudo inside this execution environment."""
+ if not self._sudo_nopasswd_probe_supported:
+ return False
try:
proc = self._run_bash(
"sudo -n true",
diff --git a/tools/environments/docker.py b/tools/environments/docker.py
index 6ef7e611232..150e5371cb7 100644
--- a/tools/environments/docker.py
+++ b/tools/environments/docker.py
@@ -486,6 +486,7 @@ class DockerEnvironment(BaseEnvironment):
size-limited tmpfs). The container is the security boundary — its filesystem stays
writable so agents can install packages. Persistence bind-mounts /workspace and /root."""
+ _sudo_nopasswd_probe_supported = True
_profile_scoped_passthrough = True
def _additional_profile_scoped_passthrough_names(self) -> tuple[str, ...]:
diff --git a/tools/environments/local.py b/tools/environments/local.py
index d5158bf1e1d..ecc9d6f3ba6 100644
--- a/tools/environments/local.py
+++ b/tools/environments/local.py
@@ -687,6 +687,7 @@ class LocalEnvironment(BaseEnvironment):
the session snapshot preserves env vars across calls; CWD persists via the
stdout marker."""
+ _sudo_nopasswd_probe_supported = True
_profile_scoped_passthrough = True
# Commands run on the Hermes host itself — controller-side platform behavior
# (macOS TCC pruning, etc.) legitimately applies here.
diff --git a/tools/environments/singularity.py b/tools/environments/singularity.py
index bb16e26fca6..2f0bf5818bb 100644
--- a/tools/environments/singularity.py
+++ b/tools/environments/singularity.py
@@ -138,6 +138,8 @@ class SingularityEnvironment(BaseEnvironment):
Session snapshot preserves env vars across calls; CWD persists via in-band stdout markers.
"""
+ _sudo_nopasswd_probe_supported = True
+
def __init__(self, image: str, cwd: str = "~", timeout: int = 60, cpu: float = 0,
memory: int = 0, disk: int = 0, persistent_filesystem: bool = False,
task_id: str = "default"):
diff --git a/tools/environments/ssh.py b/tools/environments/ssh.py
index 290b81af49f..434882b0da9 100644
--- a/tools/environments/ssh.py
+++ b/tools/environments/ssh.py
@@ -53,6 +53,7 @@ class SSHEnvironment(BaseEnvironment):
# Passthrough values are re-forwarded on every command (see _run_bash), so like docker/local
# they stay out of the remote snapshot under multiplex.
_profile_scoped_passthrough = True
+ _sudo_nopasswd_probe_supported = True
def __init__(self, host: str, user: str, cwd: str = "~",
timeout: int = 60, port: int = 22, key_path: str = "",