Repository navigation
Conversation
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Critical capacity-accounting and lifecycle bugs can block sandbox creation indefinitely, leak live sandboxes, and leave cancelled commands running when pooled sandboxes are reused.
5 open issues
What changed in this PR
Adds an optional E2B-compatible remote backend for official E2B and Aliyun Agent Sandbox, integrating with existing factories, managers, and tools without requiring a local Docker daemon.
Changes:
- Adds typed configuration, SDK connection handling, template resolution, remote execution, and archive uploads.
- Integrates remote sandbox management, concurrency limits, pools, and existing shell/Python tools.
- Adds fake-provider regression tests, an optional SDK dependency, and Docker capability forwarding.
| File | Description |
|---|---|
tests/test_tool.py |
Updates expected Python tool backend compatibility. |
tests/test_e2b_sandbox.py |
Tests remote execution, lifecycle, pools, and SDK failures with fakes. |
tests/test_e2b_helpers.py |
Tests endpoint handling and deterministic template names. |
pyproject.toml |
Adds the E2B extra and Hypothesis test dependency. |
ms_enclave/sandbox/utils/e2b_helpers.py |
Adds image, endpoint, naming, and redaction helpers. |
ms_enclave/sandbox/tools/sandbox_tools/shell_executor.py |
Enables shell execution on E2B. |
ms_enclave/sandbox/tools/sandbox_tools/python_executor.py |
Enables Python execution on E2B. |
ms_enclave/sandbox/model/config.py |
Adds E2B configuration models and Docker capabilities. |
ms_enclave/sandbox/model/base.py |
Adds E2B sandbox and manager types. |
ms_enclave/sandbox/model/__init__.py |
Exports E2B configuration models. |
ms_enclave/sandbox/manager/e2b_manager.py |
Adds remote lifecycle, capacity limits, and pool integration. |
ms_enclave/sandbox/manager/__init__.py |
Exports the E2B manager. |
ms_enclave/sandbox/boxes/e2b_template.py |
Resolves, builds, and caches remote templates. |
ms_enclave/sandbox/boxes/e2b_sandbox.py |
Implements remote commands, uploads, and lifecycle operations. |
ms_enclave/sandbox/boxes/e2b_connection.py |
Isolates optional SDK imports, connection settings, and retries. |
ms_enclave/sandbox/boxes/docker_sandbox.py |
Forwards configured additional Linux capabilities. |
ms_enclave/sandbox/boxes/base.py |
Adds typed E2B configuration handling to the factory. |
ms_enclave/sandbox/boxes/__init__.py |
Exports and registers the E2B sandbox. |
Review effort: Balanced
Comment on lines
+176
to
+177
| except Exception as exc: | ||
| return self._result(command, ExecutionStatus.ERROR, -1, '', self._conn.redact(str(exc)), started) |
Comment on lines
+70
to
+71
| await self._templates.resolve(cfg, run_id=self.run_id) | ||
| await self._slots.acquire() |
| except BaseException: | ||
| self._slots.release() | ||
| raise | ||
| self._sandboxes[sandbox.id] = sandbox |
| await sandbox.stop() | ||
| finally: | ||
| self._sandbox_locks.pop(sandbox_id, None) | ||
| self._slots.release() |
Comment on lines
+100
to
+103
| size = pool_size or self.config.pool_size | ||
| if size > self.config.max_sandboxes: | ||
| raise ValueError(f'pool_size={size} exceeds E2B max_sandboxes={self.config.max_sandboxes}') | ||
| return await super().initialize_pool(pool_size, sandbox_type or SandboxType.E2B, config) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

What changes
Add an optional E2B-compatible remote backend so callers can run existing sandbox tools and upload directories without a local Docker daemon. It supports official E2B and Aliyun Agent Sandbox through the existing sandbox/manager factories and typed configuration models.
cap_addforwarding, used by the SWE-bench harness. Allow explicitNoneCPU/memory limits so the companion grader can preserve the original unrestricted Docker behavior; existing Docker defaults remain 4 GiB / 2 CPUs.Install the optional SDK with
pip install 'ms-enclave[e2b]'on Python 3.11+. The base package continues to support Python 3.10 without the E2B extra.Validation
pytest tests/test_e2b_helpers.py tests/test_e2b_sandbox.py tests/test_tool.py -q -p no:warnings: 59 passed using Python 3.12 (eval312), including cached local Docker/notebook tool regressions. Backend tests use fakes and do not call paid services.make lint: passed with all new files staged.Memory=0,CpuQuota=0). CI lint passed on20aace6b4cf564984a27ccb2cd710fc9c5f985a1.SYS_ADMINverification passed. Large official benchmark Docker image comparisons were skipped by agreement because downloads were too slow; no official Docker scoring-parity claim is made.Integration
EvalScope's companion PR #2036 uses this backend and supplies its bundled converted-image mapping. The E2B classes/configuration must be available in an ms-enclave release before the companion integration can use a normal PyPI installation. No release version has been guessed or published by this PR.
Normal shutdown attempts one kill per owned sandbox; a failed kill is logged and fixed provider lifetime remains a fallback. Removing a local handle does not prove provider cleanup succeeded; the real cleanup checks queried provider state and found no remaining resources from the validation runs.