From 299895f2195b667c72068adf7b1c69e0a5cb2cb4 Mon Sep 17 00:00:00 2001 From: Huanyi Xie <74809554+xiehuanyi@users.noreply.github.com> Date: Wed, 7 Oct 2026 13:38:41 +0300 Subject: [PATCH] docs: make the E2B streaming example runnable --- README.md | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 724ade1..2fa9f36 100644 --- a/README.md +++ b/README.md @@ -639,22 +639,27 @@ asyncio.run(main()) ```python import asyncio +import shlex +from sandboxes import SandboxConfig from sandboxes.providers import E2BProvider async def main(): provider = E2BProvider() - sandbox = await provider.create_sandbox() - - # Stream output as it's generated - async for chunk in provider.stream_execution( - sandbox.id, - "for i in range(10): print(i); time.sleep(1)" - ): - print(chunk, end="") + sandbox = await provider.create_sandbox(SandboxConfig()) + try: + command = "python3 -u -c " + shlex.quote( + "import time\nfor i in range(10):\n print(i)\n time.sleep(1)" + ) + async for chunk in provider.stream_execution(sandbox.id, command): + print(chunk, end="") + finally: + await provider.destroy_sandbox(sandbox.id) asyncio.run(main()) ``` +For E2B, `stream_execution` yields output chunks after the command completes. + ### Connection Pooling ```python