|
| 1 | +# Cloud end-to-end practice |
| 2 | + |
| 3 | +Run the repository's cloud examples against a real sandbox on the default provider, **Alibaba Cloud Express** (`alicloud-express`). Do not push an image to ACR. |
| 4 | + |
| 5 | +> 中文版: [../../zh/guide/cloud-examples.md](../../zh/guide/cloud-examples.md) |
| 6 | +
|
| 7 | +The Agents API case is not repeated here. For the request sequence, the local stand-in CLIs, and a run that does not read a model key, see [Agents API](agents-api.md). The Chinese page is [Agents API(中文)](../../zh/guide/agents-api.md). |
| 8 | + |
| 9 | +## Setup |
| 10 | + |
| 11 | +The client reads `EBX_SANDBOX_API_KEY`. The current client does not treat `E2B_API_KEY` as the sandbox key. |
| 12 | + |
| 13 | +```bash |
| 14 | +pip install "easy-sandbox[declarative]" |
| 15 | +export EBX_SANDBOX_API_KEY="your-api-key" |
| 16 | +``` |
| 17 | + |
| 18 | +When `EBX_PROVIDER` is unset, `Sandbox.create` uses `alicloud-express`. The scripts below pass `timeout` to `Sandbox.create` (sandbox TTL, in seconds, from 60 to 900) and destroy the sandbox when the `async with` block or the `@sandbox` decorator finishes. |
| 19 | + |
| 20 | +From this repo, before `pip install`: |
| 21 | + |
| 22 | +```bash |
| 23 | +export PYTHONPATH=client-sdk/src:server-sdk/src |
| 24 | +``` |
| 25 | + |
| 26 | +## Run these |
| 27 | + |
| 28 | +From the `python-sdk` directory: |
| 29 | + |
| 30 | +```bash |
| 31 | +python examples/quickstart/03_web_service.py |
| 32 | +python examples/quickstart/04_data_analysis.py |
| 33 | +python examples/quickstart/05_decorator_usage.py |
| 34 | +python examples/compat-demos/comparison.py |
| 35 | +python examples/compat-demos/e2b_data_analysis.py |
| 36 | +python examples/compat-demos/e2b_web_scraper.py |
| 37 | +python examples/compat-demos/modal_compute.py |
| 38 | +python examples/compat-demos/modal_data_analysis.py |
| 39 | +``` |
| 40 | + |
| 41 | +| Script | What it does in the cloud | |
| 42 | +|---|---| |
| 43 | +| `examples/quickstart/03_web_service.py` | Template `node-web`. Writes an Express app, runs `npm install`, curls `localhost:3000` inside the sandbox | |
| 44 | +| `examples/quickstart/04_data_analysis.py` | Template `base`. Installs pandas, analyzes a CSV, then `run_code()` for the top three rows | |
| 45 | +| `examples/quickstart/05_decorator_usage.py` | `@sandbox` on `code-interpreter-v1`: π, a pandas summary, Fibonacci, environment variables | |
| 46 | +| `examples/compat-demos/comparison.py` | The same tasks with imperative `Sandbox.create` and with `@sandbox` | |
| 47 | +| `examples/compat-demos/e2b_data_analysis.py` | Imperative: upload a CSV, write a pandas report, read the report back | |
| 48 | +| `examples/compat-demos/e2b_web_scraper.py` | Imperative: request `https://example.com` from inside the sandbox | |
| 49 | +| `examples/compat-demos/modal_compute.py` | `@sandbox`: Monte Carlo π, matrix multiply, distribution fit | |
| 50 | +| `examples/compat-demos/modal_data_analysis.py` | `@sandbox`: sales summary, data quality, product rank | |
| 51 | + |
| 52 | +On `base`, `run_code()` in `04_data_analysis.py` can see HTTP 404 from the code-interpreter port. The client falls back to the shell, and the example still prints the table. |
| 53 | + |
| 54 | +If create fails, read the error code on the exception (a missing template is `E2001`) and stop that example. Do not switch to pushing an image. |
| 55 | + |
| 56 | +## Two agent examples |
| 57 | + |
| 58 | +Both can start without a paid model key. Set a model key only when you want a real model call. |
| 59 | + |
| 60 | +- `examples/agents/codex_agent.py` uses template `codex`. If that template is not on the account, `Sandbox.create` fails with `E2001` and the script's simulation branch never runs. `OPENAI_API_KEY` is required only for the live model branch. |
| 61 | +- `examples/agents/browser_automation.py` does not read a model key. It `pip install`s Playwright on `base`, then runs `playwright install chromium`. If `playwright` is not on `PATH`, `commands.run` raises `E3006` (`exec: "playwright": executable file not found in $PATH`). The `async with` block still destroys the sandbox. |
| 62 | + |
| 63 | +For Codex and Qwen Code HTTP sessions inside a sandbox, use `examples/agents/complete_case.py` from [Agents API](agents-api.md). |
0 commit comments