Skip to content

feat: add e2b-haystack integration for E2B cloud sandbox tools#3195

Open
tholor wants to merge 8 commits intomainfrom
add-e2b-integration
Open

feat: add e2b-haystack integration for E2B cloud sandbox tools#3195
tholor wants to merge 8 commits intomainfrom
add-e2b-integration

Conversation

@tholor
Copy link
Copy Markdown
Member

@tholor tholor commented Apr 21, 2026

Summary

Migrates the E2B sandbox toolset prototype from deepset-ai/haystack-experimental#448 into a proper e2b-haystack integration package.

  • Adds E2BSandbox for managing the lifecycle of an E2B cloud sandbox (lazy warm_up, close, full serialisation round-trip)
  • Adds four Haystack Tool subclasses that share a single sandbox instance: RunBashCommandTool, ReadFileTool, WriteFileTool, ListDirectoryTool
  • Adds E2BToolset (a Toolset subclass) that bundles all four tools as a convenience — just pass E2BToolset() to any Haystack Agent
  • Follows the haystack_integrations/tools/ module path convention (same as mcp-haystack and github-haystack)

Test plan

  • 38 unit tests pass (hatch run test:unit) — all sandbox calls are mocked, no API key needed
  • Lint clean (hatch run fmt-check)
  • Review examples in integrations/e2b/examples/ for correctness
  • Manual smoke test with a real E2B API key (integration test, requires E2B_API_KEY)
  • Maintainer to add E2B_API_KEY secret to GitHub repo for CI integration tests

🤖 Generated with Claude Code

Introduces `e2b-haystack`, a new integration that provides E2B cloud
sandbox tools for Haystack agents. Migrated from
deepset-ai/haystack-experimental#448.

Exposes four tools sharing a single `E2BSandbox` instance:
- `RunBashCommandTool` - execute bash commands
- `ReadFileTool` - read sandbox filesystem files
- `WriteFileTool` - write sandbox filesystem files
- `ListDirectoryTool` - list directory contents

Plus `E2BToolset` as a convenience Toolset bundling all four tools.
Includes 38 unit tests, two usage examples, and full serialisation
round-trip support.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@github-actions github-actions Bot added topic:CI type:documentation Improvements or additions to documentation labels Apr 21, 2026
- Add mypy override to ignore missing stubs for `e2b` package (which
  doesn't ship a py.typed marker or type stubs)
- Quote \$GITHUB_OUTPUT in workflow to fix actionlint/shellcheck SC2086

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 21, 2026

Coverage report (e2b)

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  integrations/e2b/src/haystack_integrations/tools/e2b
  bash_tool.py 53-55, 85, 93-94
  e2b_sandbox.py
  list_directory_tool.py 72, 80-81
  read_file_tool.py 67, 75-76
  sandbox_toolset.py 74, 78, 82, 90-92
  write_file_tool.py 67, 75-76
Project Total  

This report was generated by python-coverage-comment-action

tholor and others added 6 commits April 22, 2026 10:30
Gate the "Run integration tests" CI step on the E2B_API_KEY env var
being present, matching the pattern used by other integrations (e.g.
cohere). Without this the step exits with code 5 (no tests collected)
because there are no integration-marked tests and no API key is
configured yet.

Also exposes E2B_API_KEY from secrets at the workflow env level so
it will be available once a maintainer adds the secret to the repo.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds real end-to-end integration tests (marked @pytest.mark.integration)
that exercise all four tools against a live E2B sandbox:
- RunBashCommandTool: echo, non-zero exit code, stderr capture
- WriteFileTool + ReadFileTool: round-trip, nested directory creation
- ListDirectoryTool: list /tmp, list after write
- E2BToolset: warm_up/close lifecycle, shared sandbox state across tools

Also suppresses S108 (/tmp path warning) in test per-file-ignores — /tmp
is correct and intentional inside a sandboxed environment.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The e2b SDK raises CommandExitException (with exit_code/stdout/stderr
attributes) instead of returning a result for non-zero exit codes. Detect
this via duck-typing and return the formatted result string so the LLM can
see and react to the exit status, rather than propagating a ToolInvocationError.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Toolset was introduced in haystack-ai 2.19.0. The previous lower bound
of 2.12.0 caused an ImportError on the "lowest direct dependencies" CI
run. This matches the floor already used by the mcp integration.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
e2b 1.x does not have the Sandbox.create() classmethod — it was
introduced in 2.0.0. The lowest-direct-dependency CI job resolves
e2b>=1.0.0 to 1.0.0, causing AttributeError when mock.patch tries to
patch Sandbox.create. Bumping the floor to >=2.0.0 fixes the lowest-
direct run while keeping Python 3.9+ compatibility (e2b 2.x requires >=3.9).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@socket-security
Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addede2b@​2.20.077100100100100

View full report

@tholor tholor marked this pull request as ready for review April 22, 2026 12:09
@tholor tholor requested a review from a team as a code owner April 22, 2026 12:09
@tholor tholor requested review from bogdankostic and removed request for a team April 22, 2026 12:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

topic:CI type:documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant