|
2 | 2 |
|
3 | 3 | This is the template for the E2B Desktop Sandbox. |
4 | 4 |
|
5 | | -## Building the template |
| 5 | +## Building the production template |
| 6 | + |
| 7 | +To build the official `desktop` template from this repo, use `build_prod.py`. |
| 8 | +This is the script CI and releases run. |
| 9 | + |
| 10 | +1. Install the build dependencies: |
6 | 11 |
|
7 | 12 | ```bash |
8 | | -poetry run python build_dev.py |
| 13 | +poetry install |
| 14 | +``` |
| 15 | + |
| 16 | +2. Provide your credentials in `.env`: |
| 17 | + |
| 18 | +``` |
| 19 | +E2B_API_KEY=e2b_*** |
9 | 20 | ``` |
10 | 21 |
|
11 | | -## Building the production image |
| 22 | +3. Build the template: |
12 | 23 |
|
13 | 24 | ```bash |
14 | 25 | poetry run python build_prod.py |
15 | 26 | ``` |
| 27 | + |
| 28 | +During development you can build the `desktop-dev` template instead: |
| 29 | + |
| 30 | +```bash |
| 31 | +poetry run python build_dev.py |
| 32 | +``` |
| 33 | + |
| 34 | +If you want to customize the Desktop sandbox (e.g.: add a preinstalled package) |
| 35 | +you can do that by creating a [custom sandbox template](https://e2b.dev/docs/template/quickstart). |
| 36 | + |
| 37 | +## Creating a custom template |
| 38 | + |
| 39 | +1. Install E2B SDK |
| 40 | + |
| 41 | +```bash |
| 42 | +pip install e2b dotenv |
| 43 | +``` |
| 44 | + |
| 45 | +2. Create a custom sandbox template: |
| 46 | + |
| 47 | +**template.py** |
| 48 | + |
| 49 | +```python |
| 50 | +from e2b import Template |
| 51 | + |
| 52 | +template = Template().from_template("desktop") |
| 53 | +``` |
| 54 | + |
| 55 | +3. Create a build script: |
| 56 | + |
| 57 | +**build.py** |
| 58 | + |
| 59 | +```python |
| 60 | +from dotenv import load_dotenv |
| 61 | +from template import template |
| 62 | +from e2b import Template, default_build_logger |
| 63 | + |
| 64 | +load_dotenv() |
| 65 | + |
| 66 | +Template.build( |
| 67 | + template, |
| 68 | + alias="desktop-custom", |
| 69 | + cpu_count=8, |
| 70 | + memory_mb=8192, |
| 71 | + on_build_logs=default_build_logger(), |
| 72 | +) |
| 73 | +``` |
| 74 | + |
| 75 | +4. Set your environment variables in a `.env` file (loaded by `load_dotenv()`): |
| 76 | + |
| 77 | +``` |
| 78 | +E2B_API_KEY=e2b_*** |
| 79 | +``` |
| 80 | + |
| 81 | +5. Build the template: |
| 82 | + |
| 83 | +```bash |
| 84 | +python build.py |
| 85 | +``` |
| 86 | + |
| 87 | +6. Use the custom template: |
| 88 | + |
| 89 | +**Python** |
| 90 | + |
| 91 | +```python |
| 92 | +from e2b_desktop import Sandbox |
| 93 | + |
| 94 | +desktop = Sandbox.create(template="desktop-custom") |
| 95 | +``` |
| 96 | + |
| 97 | +**JavaScript** |
| 98 | + |
| 99 | +```javascript |
| 100 | +import { Sandbox } from '@e2b/desktop' |
| 101 | + |
| 102 | +const desktop = await Sandbox.create('desktop-custom') |
| 103 | +``` |
0 commit comments