Conversation
5272a96 to
2c6f8c4
Compare
There was a problem hiding this comment.
Pull request overview
This PR adds a self-contained Python example showing how to run the Kimi Agent SDK inside an E2B sandbox by vendoring an E2BKaos KAOS backend and wiring it into the example.
Changes:
- Add an
E2BKaosimplementation that adapts KAOS filesystem/process APIs to an E2BAsyncSandbox. - Add an example driver script, agent configuration, and example-local
pyproject.tomlto run the SDK in an E2B sandbox. - Update the top-level README to list the new Python example alongside existing Go examples.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| examples/python/e2b-sandbox/pyproject.toml | Defines an example-local project, Python version, and dependencies (including e2b and the local kimi-agent-sdk source) to make the sandbox example self-contained. |
| examples/python/e2b-sandbox/main.py | Implements the async entrypoint that validates E2B_API_KEY, configures workdir, creates an E2B sandbox, installs E2BKaos as the current KAOS backend, and runs the SDK prompt loop. |
| examples/python/e2b-sandbox/e2b_kaos.py | Provides the E2BKaos KAOS backend, mapping KAOS operations (paths, stat, file IO, mkdir, exec) onto the E2B sandbox APIs, with async process/stdin/stdout handling. |
| examples/python/e2b-sandbox/agent.yaml | Configures an e2b agent profile extending the default and disables the Grep tool for non-local KAOS usage. |
| examples/python/e2b-sandbox/README.md | Documents KAOS, explains how E2B integration works, provides a code snippet, and adds end-to-end run instructions for the example. |
| README.md | Adds a concise “Examples” section linking to existing Go examples and the new Python E2B sandbox example. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| ```python | ||
| from e2b import AsyncSandbox | ||
| from kaos import set_current_kaos | ||
| from kaos.path import KaosPath | ||
| from kimi_agent_sdk import prompt | ||
|
|
||
| # Create an E2B sandbox and install as KAOS backend | ||
| sandbox = await AsyncSandbox.create() | ||
| set_current_kaos(E2BKaos(sandbox, cwd="/home/user")) | ||
|
|
||
| # Agent tools now operate inside the sandbox | ||
| async for msg in prompt("Create a Python project", work_dir=KaosPath("/home/user")): | ||
| print(msg.extract_text(), end="") | ||
| ``` |
There was a problem hiding this comment.
In the "How It Works" code snippet, E2BKaos is used but never imported, so readers copying this snippet as-is will get a NameError. Please add the missing import (e.g., importing E2BKaos from e2b_kaos) to keep the example self-contained and runnable.
| uv run main.py | ||
| ``` | ||
|
|
||
| If `E2B_SANDBOX_ID` is not set, the script creates a sandbox and prints the ID. The sandbox lifecycle is managed outside of the SDK. |
There was a problem hiding this comment.
The README suggests that setting E2B_SANDBOX_ID will cause the script to connect to an existing sandbox ("If E2B_SANDBOX_ID is not set, the script creates a sandbox..."), but main.py's _get_sandbox currently ignores E2B_SANDBOX_ID and always calls AsyncSandbox.create. Please either implement the E2B_SANDBOX_ID connect flow in _get_sandbox (as hinted in the commented-out code) or update this section of the README to reflect the current behavior so users are not misled.
| If `E2B_SANDBOX_ID` is not set, the script creates a sandbox and prints the ID. The sandbox lifecycle is managed outside of the SDK. | |
| This example currently always creates a new sandbox instance and prints its ID; `E2B_SANDBOX_ID` is reserved for future use, and the sandbox lifecycle is managed outside of the SDK. |
Summary
E2BKaos(KAOS backend) implementation into the example as a reference for extending KAOS:examples/python/e2b-sandbox/e2b_kaos.py.kaos.contrib.e2b/ nokimi-clidev-branch pin).Files
examples/python/e2b-sandbox/e2b_kaos.py: vendoredE2BKaosbackendexamples/python/e2b-sandbox/main.py:set_current_kaos(E2BKaos(...))examples/python/e2b-sandbox/README.md: setup & runREADME.md: list Python examplesReference
Testing
cd python && uv sync --frozen && uv run ruff check && uv run pyright && uv run pytest -qE2B_API_KEY+ a live sandbox)