Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

fix(dify-agent): verify E2B binding Home as well as Workspace on acquire (#44014)

D41910e421dcc1f532
diff --git a/dify-agent/src/dify_agent/runtime_backend/e2b.py b/dify-agent/src/dify_agent/runtime_backend/e2b.py
index 27be29c68ac..8b2e5174e78 100644
--- a/dify-agent/src/dify_agent/runtime_backend/e2b.py
+++ b/dify-agent/src/dify_agent/runtime_backend/e2b.py
@@ -284,8 +284,10 @@ class E2BExecutionBindingBackend:
lease: E2BRuntimeLease | None = None
try:
sandbox = await self.control_plane.connect(binding_ref, timeout=self.active_timeout_seconds)
- if not await sandbox.files.exists(self.layout.workspace_dir):
- raise BindingLostError(f"E2B Binding {binding_ref!r} no longer contains its Workspace")
+ if not await sandbox.files.exists(self.layout.home_dir) or not await sandbox.files.exists(
+ self.layout.workspace_dir
+ ):
+ raise BindingLostError(f"E2B Binding {binding_ref!r} no longer contains its Home or Workspace")
lease = await self._lease(sandbox)
await _wait_for_shellctl_ready(lease.data_plane.client)
return lease
diff --git a/dify-agent/tests/local/dify_agent/runtime_backend/test_e2b.py b/dify-agent/tests/local/dify_agent/runtime_backend/test_e2b.py
index 3bc46d033e7..5b0386108b9 100644
--- a/dify-agent/tests/local/dify_agent/runtime_backend/test_e2b.py
+++ b/dify-agent/tests/local/dify_agent/runtime_backend/test_e2b.py
@@ -221,6 +221,7 @@ def _binding_backend(control: _ControlPlane) -> E2BExecutionBindingBackend:
def _connected_backend(*, pause_error: Exception | None = None) -> tuple[E2BExecutionBindingBackend, _Sandbox]:
control = _ControlPlane()
sandbox = _Sandbox(sandbox_id="sandbox-1", pause_error=pause_error)
+ sandbox.files.paths.add("/home/dify")
sandbox.files.paths.add("/workspace")
control.sandboxes[sandbox.sandbox_id] = sandbox
return _binding_backend(control), sandbox
@@ -1003,6 +1004,18 @@ async def test_e2b_acquire_fails_closed_without_traffic_token(
assert sandbox.pauses == ["full"]
[email protected]("missing_dir", ["/home/dify", "/workspace"])
+async def test_e2b_acquire_treats_missing_home_or_workspace_as_binding_lost(missing_dir: str) -> None:
+ backend, sandbox = _connected_backend()
+ sandbox.files.paths.discard(missing_dir)
+
+ with pytest.raises(BindingLostError, match="Home or Workspace"):
+ _ = await backend.acquire("sandbox-1")
+
+ assert sandbox.pauses == ["full"]
+
+
@pytest.mark.anyio
async def test_e2b_acquire_closes_transport_and_pauses_after_readiness_retries_exhausted(
monkeypatch: pytest.MonkeyPatch,