Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down