Add Moss E2B cookbook example#256
Open
Luffy2208 wants to merge 3 commits into
Open
Conversation
Contributor
|
@Luffy2208 please update the pr as per copliot comments |
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new Python cookbook under examples/cookbook/e2b/ demonstrating a “self-healing code agent” workflow that combines Moss semantic code retrieval with E2B sandbox execution to validate LLM-proposed patches in an isolated environment.
Changes:
- Introduces the
examples/cookbook/e2b/cookbook (agent entrypoint, Moss indexing helpers, E2B sandbox runner, and mocked integration tests). - Adds an intentionally broken
sample_project/used to demonstrate failing → patched → passing test validation. - Updates the root
README.mdto list the new E2B cookbook.
Reviewed changes
Copilot reviewed 12 out of 13 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| README.md | Adds the E2B cookbook entry to the root examples/integrations listing. |
| examples/cookbook/e2b/README.md | Documents setup, env vars, usage, and the Moss+Groq+E2B flow. |
| examples/cookbook/e2b/.env.example | Provides required/optional environment variables for the cookbook. |
| examples/cookbook/e2b/pyproject.toml | Defines cookbook dependencies, dev extras, and pytest/ruff config. |
| examples/cookbook/e2b/uv.lock | Locks cookbook dependencies for reproducible installs. |
| examples/cookbook/e2b/code_index.py | Scans source files and builds Moss DocumentInfo records + query helpers. |
| examples/cookbook/e2b/sandbox_runner.py | Wraps E2B sandbox creation, file copying, command execution, and patch parsing/apply. |
| examples/cookbook/e2b/code_agent.py | Main runnable agent: retrieve context via Moss, request patch via Groq, validate in E2B. |
| examples/cookbook/e2b/test_integration.py | Mocked tests for scanning/copying/patch parsing/safety without credentials. |
| examples/cookbook/e2b/sample_project/pyproject.toml | Minimal metadata for the demo project. |
| examples/cookbook/e2b/sample_project/src/ledger/init.py | Exposes the sample project API surface. |
| examples/cookbook/e2b/sample_project/src/ledger/totals.py | Contains the intentionally broken tax logic used by the demo. |
| examples/cookbook/e2b/sample_project/tests/test_totals.py | Tests that fail before the patch and pass after applying the fix. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+25
to
+26
| [tool.setuptools] | ||
| py-modules = ["code_agent", "code_index", "sandbox_runner", "test_integration"] |
| relative_path = path.relative_to(root).as_posix() | ||
| content = path.read_text(encoding="utf-8") | ||
| digest = hashlib.sha1(content.encode("utf-8")).hexdigest()[:12] | ||
| symbols = extract_python_symbols(content) if path.suffix == ".py" else [] |
Comment on lines
+92
to
+94
| return client, False | ||
| except Exception: | ||
| print("Reusable Moss index not found; creating it...") |
0505511 to
1597d9c
Compare
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.
Pull Request Checklist
Please ensure that your PR meets the following requirements:
Description
Adds a new
examples/cookbook/e2b/cookbook that demonstrates how to combine Moss semantic code search with E2B cloud execution sandboxes for a self-healing code agent workflow.Fixes #199
What this adds
This cookbook shows the full Moss + LLM + E2B pattern requested in the issue:
Files added
examples/cookbook/e2b/README.mdexamples/cookbook/e2b/.env.exampleProvides the required environment variables:
MOSS_PROJECT_IDMOSS_PROJECT_KEYE2B_API_KEYGROQ_API_KEYIncludes optional variables:
GROQ_MODELMOSS_INDEX_NAMEexamples/cookbook/e2b/pyproject.tomlDefines the cookbook package and dependencies.
Runtime dependencies
mosse2bgroqpython-dotenvOptional development dependencies
pytestruffAlso adds pytest config so plain
pytestruns the cookbook helper tests instead of the intentionally broken sample project.examples/cookbook/e2b/uv.lockLocks dependencies for reproducible
uvsetup, consistent with the Daytona cookbook style.examples/cookbook/e2b/code_index.pyDocumentInforecords.examples/cookbook/e2b/sandbox_runner.py.env, virtualenvs, caches, large files, and generated folders.examples/cookbook/e2b/code_agent.pyMain runnable example that:
.envexamples/cookbook/e2b/test_integration.pyAdds mocked tests that do not require Moss, Groq, or E2B credentials.
Covers
examples/cookbook/e2b/sample_project/Adds a tiny intentionally broken Python project used by the demo.
src/ledger/totals.py, where tax is incorrectly treated as a flat amount.tests/test_totals.pyfail before the patch and pass after the agent applies the source fix.Root
README.mdAdds the E2B cookbook to the examples list and integration table.
Testing performed
Local no-credential checks
uv sync --extra dev uv run python test_integration.py uv run python -m pytest -q uv run python -m ruff check .Results
Live end-to-end validation
Also performed with real Moss, Groq, and E2B credentials:
Verified behavior
Reusable index flow
Verified reusable-index behavior
Notes
The bundled
sample_projectis intentionally broken. Running its tests directly is expected to fail before the agent patches it.The cookbook’s own tests are scoped to
test_integration.py.Type of Change