Open-source AI penetration testing tool to find and fix your app’s vulnerabilities.
Python agentsai-hackingai-penetration-testingai-pentestingai-securityartificial-intelligencebug-bountycode-qualityctf-toolscybersecuritycybersecurity-toolsethical-hackinghackingllm-securityoffensive-securitypenetration-testingpentesting-toolsred-teamingsecuritysecurity-automation
Swallow sandbox container races in the stream consumer (#552)
Ahmed Allam62021310289d
diff --git a/strix/core/agents.py b/strix/core/agents.pyindex 6aa5801c..298aa2be 100644--- a/strix/core/agents.py+++ b/strix/core/agents.py@@ -42,10 +42,14 @@ class AgentCoordinator:self.runtimes: dict[str, AgentRuntime] = {}self._lock = asyncio.Lock()self._snapshot_path: Path | None = None+ self.is_shutting_down = Falsedef set_snapshot_path(self, path: Path) -> None:self._snapshot_path = path+ def mark_shutting_down(self) -> None:+ self.is_shutting_down = True+async def register(self,agent_id: str,diff --git a/strix/core/execution.py b/strix/core/execution.pyindex 1017f70d..1b561e9e 100644--- a/strix/core/execution.py+++ b/strix/core/execution.py@@ -11,6 +11,8 @@ from typing import TYPE_CHECKING, Any, castfrom agents import RunConfig, Runnerfrom agents.exceptions import AgentsException, MaxTurnsExceeded, UserError+from agents.sandbox.errors import ExecTransportError+from docker import errors as docker_errors # type: ignore[import-untyped, unused-ignore]from openai import APIErrorfrom strix.core.inputs import child_initial_input@@ -320,7 +322,7 @@ async def _run_noninteractive_until_lifecycle()-async def _run_cycle( # noqa: PLR0912+async def _run_cycle( # noqa: PLR0912, PLR0915agent: Any,coordinator: AgentCoordinator,agent_id: str,@@ -356,6 +358,8 @@ async def _run_cycle( # noqa: PLR0912event_sink(agent_id, event)except Exception:logger.exception("stream event sink failed for %s", agent_id)+ if stream.run_loop_exception is not None:+ raise stream.run_loop_exceptionexcept RuntimeError as stream_exc:if "after shutdown" not in str(stream_exc):raise@@ -363,8 +367,14 @@ async def _run_cycle( # noqa: PLR0912"Ignoring LiteLLM end-of-stream shutdown race for %s",agent_id,)- if stream.run_loop_exception is not None:- raise stream.run_loop_exception+ except (ExecTransportError, docker_errors.NotFound):+ if not coordinator.is_shutting_down:+ raise+ logger.warning(+ "Ignoring sandbox container error during teardown for %s",+ agent_id,+ exc_info=True,+ )finally:await coordinator.detach_stream(agent_id, stream)except Exception as exc:diff --git a/strix/interface/tui/app.py b/strix/interface/tui/app.pyindex 2b8f89b8..e8fac0e4 100644--- a/strix/interface/tui/app.py+++ b/strix/interface/tui/app.py@@ -1715,6 +1715,7 @@ class StrixTUIApp(App): # type: ignore[misc]self.exit()def _fire_sandbox_cleanup(self) -> None:+ self.coordinator.mark_shutting_down()loop = self._scan_loopif loop is None or loop.is_closed():return