Skip to content

Commit 9ec6c56

Browse files
mishushakovclaude
andauthored
Document customizing the sandbox template (#210)
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
1 parent a444b9e commit 9ec6c56

2 files changed

Lines changed: 95 additions & 3 deletions

File tree

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,3 +493,7 @@ await desktop.wait(1000) // Wait for 1 second
493493

494494
The desktop-like environment is based on Linux and [Xfce](https://www.xfce.org/) at the moment. We chose Xfce because it's a fast and lightweight environment that's also popular and actively supported. However, this Sandbox template is fully customizable and you can create your own desktop environment.
495495
Check out the sandbox template's code [here](./template/).
496+
497+
## Customizing the sandbox template
498+
499+
Need extra packages or a different desktop environment? You can build your own Desktop sandbox template. See the [template guide](./template/README.md) for a step-by-step walkthrough of creating, building, and using a custom template (as well as building the production `desktop` template).

template/README.md

Lines changed: 91 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,102 @@
22

33
This is the template for the E2B Desktop Sandbox.
44

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:
611

712
```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_***
920
```
1021

11-
## Building the production image
22+
3. Build the template:
1223

1324
```bash
1425
poetry run python build_prod.py
1526
```
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

Comments
 (0)