airabox 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of airabox might be problematic. Click here for more details.
- airabox-0.1.0/PKG-INFO +350 -0
- airabox-0.1.0/README.md +330 -0
- airabox-0.1.0/__init__.py +28 -0
- airabox-0.1.0/airabox.egg-info/PKG-INFO +350 -0
- airabox-0.1.0/airabox.egg-info/SOURCES.txt +25 -0
- airabox-0.1.0/airabox.egg-info/dependency_links.txt +1 -0
- airabox-0.1.0/airabox.egg-info/requires.txt +3 -0
- airabox-0.1.0/airabox.egg-info/top_level.txt +1 -0
- airabox-0.1.0/client.py +131 -0
- airabox-0.1.0/constants.py +11 -0
- airabox-0.1.0/desktop/__init__.py +11 -0
- airabox-0.1.0/desktop/desktop_asynb.py +507 -0
- airabox-0.1.0/desktop/desktop_sync.py +398 -0
- airabox-0.1.0/mobile/__init__.py +6 -0
- airabox-0.1.0/mobile/mobile_async.py +325 -0
- airabox-0.1.0/mobile/mobile_sync.py +254 -0
- airabox-0.1.0/pyproject.toml +33 -0
- airabox-0.1.0/setup.cfg +4 -0
airabox-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: airabox
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python SDK for Airabox E2B-compatible desktop and mobile sandboxes
|
|
5
|
+
Author: Oasis Aira
|
|
6
|
+
Project-URL: Homepage, https://github.com/oasis-aira/airabox
|
|
7
|
+
Project-URL: Repository, https://github.com/oasis-aira/airabox
|
|
8
|
+
Project-URL: Issues, https://github.com/oasis-aira/airabox/issues
|
|
9
|
+
Classifier: Development Status :: 3 - Alpha
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
15
|
+
Requires-Python: >=3.11
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
Requires-Dist: e2b<3.0.0,>=2.44.0
|
|
18
|
+
Requires-Dist: httpx<1.0.0,>=0.27.0
|
|
19
|
+
Requires-Dist: e2b-code-interpreter<3.0.0,>=2.9.0
|
|
20
|
+
|
|
21
|
+
# Airabox Python SDK
|
|
22
|
+
|
|
23
|
+
Python SDK for Airabox E2B-compatible desktop and mobile sandboxes.
|
|
24
|
+
|
|
25
|
+
## Installation
|
|
26
|
+
|
|
27
|
+
Install the released package from PyPI:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
python -m pip install airabox
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
To install the current source checkout:
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
python -m pip install ./sdk/python
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Airabox requires Python 3.11 or newer. It depends directly on the official
|
|
40
|
+
`e2b` SDK and `httpx`, and does not require `a6x_desktop`.
|
|
41
|
+
|
|
42
|
+
## Build
|
|
43
|
+
|
|
44
|
+
Run the following commands from the repository root:
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
python -m pip install --upgrade build
|
|
48
|
+
python -m build --outdir dist sdk/python
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
This produces a wheel and source distribution:
|
|
52
|
+
|
|
53
|
+
```text
|
|
54
|
+
dist/airabox-0.1.0-py3-none-any.whl
|
|
55
|
+
dist/airabox-0.1.0.tar.gz
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Install the wheel in the current Python environment to verify it:
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
python -m pip install --force-reinstall dist/airabox-0.1.0-py3-none-any.whl
|
|
62
|
+
python -c "import airabox; print(airabox.__file__)"
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
The filenames include the version declared in `sdk/python/pyproject.toml` and
|
|
66
|
+
will change when that version is updated.
|
|
67
|
+
|
|
68
|
+
## Publish to PyPI
|
|
69
|
+
|
|
70
|
+
You need a PyPI account and an API token. Install the build and upload tools
|
|
71
|
+
from the repository root:
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
python -m pip install --upgrade build twine
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Build a clean set of artifacts and upload it to TestPyPI first:
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
rm -rf dist
|
|
81
|
+
python -m build --outdir dist sdk/python
|
|
82
|
+
python -m twine upload --repository testpypi dist/*
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Check the TestPyPI package in a separate environment. Because dependencies
|
|
86
|
+
such as `e2b` are published on the main PyPI index, keep the main index as an
|
|
87
|
+
extra index:
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
python -m pip install --index-url https://test.pypi.org/simple/ \
|
|
91
|
+
--extra-index-url https://pypi.org/simple/ airabox
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
After verification, upload the same artifacts to the production PyPI index:
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
python -m twine upload dist/*
|
|
98
|
+
python -m pip install --upgrade airabox
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
From the repository root, the build, metadata check, and TestPyPI upload can
|
|
102
|
+
also be run with:
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
./publish.sh
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
After verification, use the `pypi` parameter to upload to the formal PyPI
|
|
109
|
+
index:
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
./publish.sh pypi
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
The script uses `python` from the current environment. Set `PYTHON_BIN` to use
|
|
116
|
+
a different Python executable.
|
|
117
|
+
|
|
118
|
+
脚本成功后会输出实际发布地址和安装命令。默认目标是 TestPyPI;使用
|
|
119
|
+
`./publish.sh pypi` 后才会发布到正式 PyPI。
|
|
120
|
+
|
|
121
|
+
When Twine asks for credentials, enter `__token__` as the username and your
|
|
122
|
+
PyPI API token as the password. For non-interactive publishing, set
|
|
123
|
+
`TWINE_USERNAME=__token__` and `TWINE_PASSWORD` in the publishing environment,
|
|
124
|
+
or configure them in `~/.pypirc`.
|
|
125
|
+
|
|
126
|
+
PyPI versions are immutable: an existing version cannot be uploaded again.
|
|
127
|
+
Before the next release, update `version` in `pyproject.toml`, for example
|
|
128
|
+
from `0.1.0` to `0.1.1`, rebuild `dist/`, and upload the new artifacts.
|
|
129
|
+
|
|
130
|
+
## Usage
|
|
131
|
+
|
|
132
|
+
Set your API key when creating a client. When `domain` is omitted, the SDK
|
|
133
|
+
uses its configured default domain:
|
|
134
|
+
|
|
135
|
+
```python
|
|
136
|
+
from airabox import E2B
|
|
137
|
+
|
|
138
|
+
client = E2B(
|
|
139
|
+
api_key="your-api-key",
|
|
140
|
+
)
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
`E2B` exposes four sandbox families. Use the synchronous resources in regular
|
|
144
|
+
Python code and the `Async*` resources inside an async event loop.
|
|
145
|
+
|
|
146
|
+
## Base Sandbox
|
|
147
|
+
|
|
148
|
+
Base sandboxes provide the standard E2B filesystem, process, and command APIs.
|
|
149
|
+
Use `Sandbox` for general-purpose workloads that do not need a graphical
|
|
150
|
+
desktop or a code-interpreter runtime.
|
|
151
|
+
|
|
152
|
+
### Synchronous
|
|
153
|
+
|
|
154
|
+
```python
|
|
155
|
+
from airabox import E2B
|
|
156
|
+
|
|
157
|
+
client = E2B(api_key="your-api-key")
|
|
158
|
+
sandbox = client.Sandbox.create(timeout=300)
|
|
159
|
+
|
|
160
|
+
result = sandbox.commands.run("printf 'hello from Airabox\\n'")
|
|
161
|
+
print(result.stdout)
|
|
162
|
+
|
|
163
|
+
# Reuse an existing sandbox when its ID is known.
|
|
164
|
+
same_sandbox = client.Sandbox.connect(sandbox.sandbox_id)
|
|
165
|
+
print(same_sandbox.commands.run("pwd").stdout)
|
|
166
|
+
|
|
167
|
+
sandbox.kill()
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
### Asynchronous
|
|
171
|
+
|
|
172
|
+
```python
|
|
173
|
+
from airabox import E2B
|
|
174
|
+
|
|
175
|
+
client = E2B(api_key="your-api-key")
|
|
176
|
+
sandbox = await client.AsyncSandbox.create(timeout=300)
|
|
177
|
+
|
|
178
|
+
result = await sandbox.commands.run("printf 'hello from Airabox\\n'")
|
|
179
|
+
print(result.stdout)
|
|
180
|
+
|
|
181
|
+
same_sandbox = await client.AsyncSandbox.connect(sandbox.sandbox_id)
|
|
182
|
+
print((await same_sandbox.commands.run("pwd")).stdout)
|
|
183
|
+
|
|
184
|
+
await sandbox.kill()
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
## Code Interpreter Sandbox
|
|
188
|
+
|
|
189
|
+
Code Interpreter sandboxes add `run_code`, which executes Python or another
|
|
190
|
+
supported language while preserving state between executions.
|
|
191
|
+
|
|
192
|
+
### Synchronous
|
|
193
|
+
|
|
194
|
+
```python
|
|
195
|
+
from airabox import E2B
|
|
196
|
+
|
|
197
|
+
client = E2B(api_key="your-api-key")
|
|
198
|
+
sandbox = client.CodeInterpreter.create(timeout=300)
|
|
199
|
+
|
|
200
|
+
sandbox.run_code("x = 1")
|
|
201
|
+
execution = sandbox.run_code("x += 1; x")
|
|
202
|
+
print(execution.text)
|
|
203
|
+
|
|
204
|
+
sandbox.kill()
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
### Asynchronous
|
|
208
|
+
|
|
209
|
+
```python
|
|
210
|
+
from airabox import E2B
|
|
211
|
+
|
|
212
|
+
client = E2B(api_key="your-api-key")
|
|
213
|
+
sandbox = await client.AsyncCodeInterpreter.create(timeout=300)
|
|
214
|
+
|
|
215
|
+
await sandbox.run_code("x = 1")
|
|
216
|
+
execution = await sandbox.run_code("x += 1; x")
|
|
217
|
+
print(execution.text)
|
|
218
|
+
|
|
219
|
+
await sandbox.kill()
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
Use `client.CodeInterpreter.connect(sandbox_id)` or
|
|
223
|
+
`await client.AsyncCodeInterpreter.connect(sandbox_id)` to continue an
|
|
224
|
+
existing code session.
|
|
225
|
+
|
|
226
|
+
## Desktop Sandbox
|
|
227
|
+
|
|
228
|
+
Desktop sandboxes provide an XFCE desktop, mouse and keyboard controls, a
|
|
229
|
+
preview stream, and screenshots. The desktop helpers start the graphical
|
|
230
|
+
services when the sandbox is created or connected.
|
|
231
|
+
|
|
232
|
+
### Synchronous
|
|
233
|
+
|
|
234
|
+
```python
|
|
235
|
+
from pathlib import Path
|
|
236
|
+
|
|
237
|
+
from airabox import E2B
|
|
238
|
+
|
|
239
|
+
client = E2B(api_key="your-api-key")
|
|
240
|
+
desktop = client.Desktop.create(timeout=300)
|
|
241
|
+
|
|
242
|
+
print(f"sandbox_id={desktop.sandbox_id}")
|
|
243
|
+
print(f"screen_size={desktop.get_screen_size()}")
|
|
244
|
+
print(f"preview_url={desktop.stream.get_url()}")
|
|
245
|
+
desktop.stream.start()
|
|
246
|
+
|
|
247
|
+
desktop.left_click(640, 360)
|
|
248
|
+
Path("desktop.png").write_bytes(desktop.screenshot())
|
|
249
|
+
|
|
250
|
+
desktop.stream.stop()
|
|
251
|
+
desktop.kill()
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
### Asynchronous
|
|
255
|
+
|
|
256
|
+
```python
|
|
257
|
+
from pathlib import Path
|
|
258
|
+
|
|
259
|
+
from airabox import E2B
|
|
260
|
+
|
|
261
|
+
client = E2B(api_key="your-api-key")
|
|
262
|
+
desktop = await client.AsyncDesktopSandbox.create(timeout=300)
|
|
263
|
+
|
|
264
|
+
print(f"sandbox_id={desktop.sandbox_id}")
|
|
265
|
+
print(f"screen_size={await desktop.get_screen_size()}")
|
|
266
|
+
print(f"preview_url={desktop.stream.get_url()}")
|
|
267
|
+
await desktop.stream.start()
|
|
268
|
+
|
|
269
|
+
await desktop.left_click(640, 360)
|
|
270
|
+
Path("desktop.png").write_bytes(await desktop.screenshot())
|
|
271
|
+
|
|
272
|
+
await desktop.stream.stop()
|
|
273
|
+
await desktop.kill()
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
To reconnect, use `client.Desktop.connect(sandbox_id)` or
|
|
277
|
+
`await client.AsyncDesktopSandbox.connect(sandbox_id)`. Desktop click
|
|
278
|
+
coordinates are absolute screen coordinates.
|
|
279
|
+
|
|
280
|
+
## Mobile Sandbox
|
|
281
|
+
|
|
282
|
+
Mobile sandboxes provide Android controls such as tapping, swiping, key events,
|
|
283
|
+
app launching, preview streaming, and screenshots.
|
|
284
|
+
|
|
285
|
+
### Synchronous
|
|
286
|
+
|
|
287
|
+
```python
|
|
288
|
+
from pathlib import Path
|
|
289
|
+
|
|
290
|
+
from airabox import E2B
|
|
291
|
+
|
|
292
|
+
client = E2B(api_key="your-api-key")
|
|
293
|
+
mobile = client.Mobile.create(timeout=300, request_timeout=300)
|
|
294
|
+
|
|
295
|
+
print(f"sandbox_id={mobile.sandbox_id}")
|
|
296
|
+
print(f"screen_size={mobile.get_screen_size()}")
|
|
297
|
+
print(f"preview_url={mobile.stream.get_url()}")
|
|
298
|
+
mobile.stream.start()
|
|
299
|
+
|
|
300
|
+
mobile.click(540, 960)
|
|
301
|
+
Path("mobile.png").write_bytes(mobile.screenshot())
|
|
302
|
+
|
|
303
|
+
mobile.stream.stop()
|
|
304
|
+
mobile.kill()
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
### Asynchronous
|
|
308
|
+
|
|
309
|
+
```python
|
|
310
|
+
from pathlib import Path
|
|
311
|
+
|
|
312
|
+
from airabox import E2B
|
|
313
|
+
|
|
314
|
+
client = E2B(api_key="your-api-key")
|
|
315
|
+
mobile = await client.AsyncMobileSandbox.create(timeout=300)
|
|
316
|
+
|
|
317
|
+
print(f"sandbox_id={mobile.sandbox_id}")
|
|
318
|
+
print(f"screen_size={await mobile.get_screen_size()}")
|
|
319
|
+
print(f"preview_url={await mobile.stream.get_url()}")
|
|
320
|
+
await mobile.stream.start()
|
|
321
|
+
|
|
322
|
+
await mobile.click(540, 960)
|
|
323
|
+
Path("mobile.png").write_bytes(await mobile.screenshot())
|
|
324
|
+
|
|
325
|
+
await mobile.stream.stop()
|
|
326
|
+
await mobile.kill()
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
To reconnect, use `client.Mobile.connect(sandbox_id)` or
|
|
330
|
+
`await client.AsyncMobileSandbox.connect(sandbox_id)`. Mobile click and swipe
|
|
331
|
+
coordinates are absolute screen coordinates.
|
|
332
|
+
|
|
333
|
+
## Shared Resources
|
|
334
|
+
|
|
335
|
+
The client also exposes the standard E2B resources, including `Volume`,
|
|
336
|
+
`AsyncVolume`, `Template`, `AsyncTemplate`, `Secret`, and `AsyncSecret`:
|
|
337
|
+
|
|
338
|
+
```python
|
|
339
|
+
volume = client.Volume.create("my-volume")
|
|
340
|
+
template_exists = client.Template.exists("my-template")
|
|
341
|
+
secret = client.Secret.create("example-key", "example-value")
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
## Lifecycle
|
|
345
|
+
|
|
346
|
+
These snippets create sandboxes directly and explicitly call `kill()` when
|
|
347
|
+
finished. For long-lived workflows, save the sandbox ID and reconnect with the
|
|
348
|
+
matching `connect()` method shown above.
|
|
349
|
+
|
|
350
|
+
For more runnable Python examples, see [`examples/python/`](../../examples/python/).
|
airabox-0.1.0/README.md
ADDED
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
# Airabox Python SDK
|
|
2
|
+
|
|
3
|
+
Python SDK for Airabox E2B-compatible desktop and mobile sandboxes.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Install the released package from PyPI:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
python -m pip install airabox
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
To install the current source checkout:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
python -m pip install ./sdk/python
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Airabox requires Python 3.11 or newer. It depends directly on the official
|
|
20
|
+
`e2b` SDK and `httpx`, and does not require `a6x_desktop`.
|
|
21
|
+
|
|
22
|
+
## Build
|
|
23
|
+
|
|
24
|
+
Run the following commands from the repository root:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
python -m pip install --upgrade build
|
|
28
|
+
python -m build --outdir dist sdk/python
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
This produces a wheel and source distribution:
|
|
32
|
+
|
|
33
|
+
```text
|
|
34
|
+
dist/airabox-0.1.0-py3-none-any.whl
|
|
35
|
+
dist/airabox-0.1.0.tar.gz
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Install the wheel in the current Python environment to verify it:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
python -m pip install --force-reinstall dist/airabox-0.1.0-py3-none-any.whl
|
|
42
|
+
python -c "import airabox; print(airabox.__file__)"
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
The filenames include the version declared in `sdk/python/pyproject.toml` and
|
|
46
|
+
will change when that version is updated.
|
|
47
|
+
|
|
48
|
+
## Publish to PyPI
|
|
49
|
+
|
|
50
|
+
You need a PyPI account and an API token. Install the build and upload tools
|
|
51
|
+
from the repository root:
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
python -m pip install --upgrade build twine
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Build a clean set of artifacts and upload it to TestPyPI first:
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
rm -rf dist
|
|
61
|
+
python -m build --outdir dist sdk/python
|
|
62
|
+
python -m twine upload --repository testpypi dist/*
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Check the TestPyPI package in a separate environment. Because dependencies
|
|
66
|
+
such as `e2b` are published on the main PyPI index, keep the main index as an
|
|
67
|
+
extra index:
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
python -m pip install --index-url https://test.pypi.org/simple/ \
|
|
71
|
+
--extra-index-url https://pypi.org/simple/ airabox
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
After verification, upload the same artifacts to the production PyPI index:
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
python -m twine upload dist/*
|
|
78
|
+
python -m pip install --upgrade airabox
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
From the repository root, the build, metadata check, and TestPyPI upload can
|
|
82
|
+
also be run with:
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
./publish.sh
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
After verification, use the `pypi` parameter to upload to the formal PyPI
|
|
89
|
+
index:
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
./publish.sh pypi
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
The script uses `python` from the current environment. Set `PYTHON_BIN` to use
|
|
96
|
+
a different Python executable.
|
|
97
|
+
|
|
98
|
+
脚本成功后会输出实际发布地址和安装命令。默认目标是 TestPyPI;使用
|
|
99
|
+
`./publish.sh pypi` 后才会发布到正式 PyPI。
|
|
100
|
+
|
|
101
|
+
When Twine asks for credentials, enter `__token__` as the username and your
|
|
102
|
+
PyPI API token as the password. For non-interactive publishing, set
|
|
103
|
+
`TWINE_USERNAME=__token__` and `TWINE_PASSWORD` in the publishing environment,
|
|
104
|
+
or configure them in `~/.pypirc`.
|
|
105
|
+
|
|
106
|
+
PyPI versions are immutable: an existing version cannot be uploaded again.
|
|
107
|
+
Before the next release, update `version` in `pyproject.toml`, for example
|
|
108
|
+
from `0.1.0` to `0.1.1`, rebuild `dist/`, and upload the new artifacts.
|
|
109
|
+
|
|
110
|
+
## Usage
|
|
111
|
+
|
|
112
|
+
Set your API key when creating a client. When `domain` is omitted, the SDK
|
|
113
|
+
uses its configured default domain:
|
|
114
|
+
|
|
115
|
+
```python
|
|
116
|
+
from airabox import E2B
|
|
117
|
+
|
|
118
|
+
client = E2B(
|
|
119
|
+
api_key="your-api-key",
|
|
120
|
+
)
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
`E2B` exposes four sandbox families. Use the synchronous resources in regular
|
|
124
|
+
Python code and the `Async*` resources inside an async event loop.
|
|
125
|
+
|
|
126
|
+
## Base Sandbox
|
|
127
|
+
|
|
128
|
+
Base sandboxes provide the standard E2B filesystem, process, and command APIs.
|
|
129
|
+
Use `Sandbox` for general-purpose workloads that do not need a graphical
|
|
130
|
+
desktop or a code-interpreter runtime.
|
|
131
|
+
|
|
132
|
+
### Synchronous
|
|
133
|
+
|
|
134
|
+
```python
|
|
135
|
+
from airabox import E2B
|
|
136
|
+
|
|
137
|
+
client = E2B(api_key="your-api-key")
|
|
138
|
+
sandbox = client.Sandbox.create(timeout=300)
|
|
139
|
+
|
|
140
|
+
result = sandbox.commands.run("printf 'hello from Airabox\\n'")
|
|
141
|
+
print(result.stdout)
|
|
142
|
+
|
|
143
|
+
# Reuse an existing sandbox when its ID is known.
|
|
144
|
+
same_sandbox = client.Sandbox.connect(sandbox.sandbox_id)
|
|
145
|
+
print(same_sandbox.commands.run("pwd").stdout)
|
|
146
|
+
|
|
147
|
+
sandbox.kill()
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### Asynchronous
|
|
151
|
+
|
|
152
|
+
```python
|
|
153
|
+
from airabox import E2B
|
|
154
|
+
|
|
155
|
+
client = E2B(api_key="your-api-key")
|
|
156
|
+
sandbox = await client.AsyncSandbox.create(timeout=300)
|
|
157
|
+
|
|
158
|
+
result = await sandbox.commands.run("printf 'hello from Airabox\\n'")
|
|
159
|
+
print(result.stdout)
|
|
160
|
+
|
|
161
|
+
same_sandbox = await client.AsyncSandbox.connect(sandbox.sandbox_id)
|
|
162
|
+
print((await same_sandbox.commands.run("pwd")).stdout)
|
|
163
|
+
|
|
164
|
+
await sandbox.kill()
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
## Code Interpreter Sandbox
|
|
168
|
+
|
|
169
|
+
Code Interpreter sandboxes add `run_code`, which executes Python or another
|
|
170
|
+
supported language while preserving state between executions.
|
|
171
|
+
|
|
172
|
+
### Synchronous
|
|
173
|
+
|
|
174
|
+
```python
|
|
175
|
+
from airabox import E2B
|
|
176
|
+
|
|
177
|
+
client = E2B(api_key="your-api-key")
|
|
178
|
+
sandbox = client.CodeInterpreter.create(timeout=300)
|
|
179
|
+
|
|
180
|
+
sandbox.run_code("x = 1")
|
|
181
|
+
execution = sandbox.run_code("x += 1; x")
|
|
182
|
+
print(execution.text)
|
|
183
|
+
|
|
184
|
+
sandbox.kill()
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
### Asynchronous
|
|
188
|
+
|
|
189
|
+
```python
|
|
190
|
+
from airabox import E2B
|
|
191
|
+
|
|
192
|
+
client = E2B(api_key="your-api-key")
|
|
193
|
+
sandbox = await client.AsyncCodeInterpreter.create(timeout=300)
|
|
194
|
+
|
|
195
|
+
await sandbox.run_code("x = 1")
|
|
196
|
+
execution = await sandbox.run_code("x += 1; x")
|
|
197
|
+
print(execution.text)
|
|
198
|
+
|
|
199
|
+
await sandbox.kill()
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
Use `client.CodeInterpreter.connect(sandbox_id)` or
|
|
203
|
+
`await client.AsyncCodeInterpreter.connect(sandbox_id)` to continue an
|
|
204
|
+
existing code session.
|
|
205
|
+
|
|
206
|
+
## Desktop Sandbox
|
|
207
|
+
|
|
208
|
+
Desktop sandboxes provide an XFCE desktop, mouse and keyboard controls, a
|
|
209
|
+
preview stream, and screenshots. The desktop helpers start the graphical
|
|
210
|
+
services when the sandbox is created or connected.
|
|
211
|
+
|
|
212
|
+
### Synchronous
|
|
213
|
+
|
|
214
|
+
```python
|
|
215
|
+
from pathlib import Path
|
|
216
|
+
|
|
217
|
+
from airabox import E2B
|
|
218
|
+
|
|
219
|
+
client = E2B(api_key="your-api-key")
|
|
220
|
+
desktop = client.Desktop.create(timeout=300)
|
|
221
|
+
|
|
222
|
+
print(f"sandbox_id={desktop.sandbox_id}")
|
|
223
|
+
print(f"screen_size={desktop.get_screen_size()}")
|
|
224
|
+
print(f"preview_url={desktop.stream.get_url()}")
|
|
225
|
+
desktop.stream.start()
|
|
226
|
+
|
|
227
|
+
desktop.left_click(640, 360)
|
|
228
|
+
Path("desktop.png").write_bytes(desktop.screenshot())
|
|
229
|
+
|
|
230
|
+
desktop.stream.stop()
|
|
231
|
+
desktop.kill()
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
### Asynchronous
|
|
235
|
+
|
|
236
|
+
```python
|
|
237
|
+
from pathlib import Path
|
|
238
|
+
|
|
239
|
+
from airabox import E2B
|
|
240
|
+
|
|
241
|
+
client = E2B(api_key="your-api-key")
|
|
242
|
+
desktop = await client.AsyncDesktopSandbox.create(timeout=300)
|
|
243
|
+
|
|
244
|
+
print(f"sandbox_id={desktop.sandbox_id}")
|
|
245
|
+
print(f"screen_size={await desktop.get_screen_size()}")
|
|
246
|
+
print(f"preview_url={desktop.stream.get_url()}")
|
|
247
|
+
await desktop.stream.start()
|
|
248
|
+
|
|
249
|
+
await desktop.left_click(640, 360)
|
|
250
|
+
Path("desktop.png").write_bytes(await desktop.screenshot())
|
|
251
|
+
|
|
252
|
+
await desktop.stream.stop()
|
|
253
|
+
await desktop.kill()
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
To reconnect, use `client.Desktop.connect(sandbox_id)` or
|
|
257
|
+
`await client.AsyncDesktopSandbox.connect(sandbox_id)`. Desktop click
|
|
258
|
+
coordinates are absolute screen coordinates.
|
|
259
|
+
|
|
260
|
+
## Mobile Sandbox
|
|
261
|
+
|
|
262
|
+
Mobile sandboxes provide Android controls such as tapping, swiping, key events,
|
|
263
|
+
app launching, preview streaming, and screenshots.
|
|
264
|
+
|
|
265
|
+
### Synchronous
|
|
266
|
+
|
|
267
|
+
```python
|
|
268
|
+
from pathlib import Path
|
|
269
|
+
|
|
270
|
+
from airabox import E2B
|
|
271
|
+
|
|
272
|
+
client = E2B(api_key="your-api-key")
|
|
273
|
+
mobile = client.Mobile.create(timeout=300, request_timeout=300)
|
|
274
|
+
|
|
275
|
+
print(f"sandbox_id={mobile.sandbox_id}")
|
|
276
|
+
print(f"screen_size={mobile.get_screen_size()}")
|
|
277
|
+
print(f"preview_url={mobile.stream.get_url()}")
|
|
278
|
+
mobile.stream.start()
|
|
279
|
+
|
|
280
|
+
mobile.click(540, 960)
|
|
281
|
+
Path("mobile.png").write_bytes(mobile.screenshot())
|
|
282
|
+
|
|
283
|
+
mobile.stream.stop()
|
|
284
|
+
mobile.kill()
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
### Asynchronous
|
|
288
|
+
|
|
289
|
+
```python
|
|
290
|
+
from pathlib import Path
|
|
291
|
+
|
|
292
|
+
from airabox import E2B
|
|
293
|
+
|
|
294
|
+
client = E2B(api_key="your-api-key")
|
|
295
|
+
mobile = await client.AsyncMobileSandbox.create(timeout=300)
|
|
296
|
+
|
|
297
|
+
print(f"sandbox_id={mobile.sandbox_id}")
|
|
298
|
+
print(f"screen_size={await mobile.get_screen_size()}")
|
|
299
|
+
print(f"preview_url={await mobile.stream.get_url()}")
|
|
300
|
+
await mobile.stream.start()
|
|
301
|
+
|
|
302
|
+
await mobile.click(540, 960)
|
|
303
|
+
Path("mobile.png").write_bytes(await mobile.screenshot())
|
|
304
|
+
|
|
305
|
+
await mobile.stream.stop()
|
|
306
|
+
await mobile.kill()
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
To reconnect, use `client.Mobile.connect(sandbox_id)` or
|
|
310
|
+
`await client.AsyncMobileSandbox.connect(sandbox_id)`. Mobile click and swipe
|
|
311
|
+
coordinates are absolute screen coordinates.
|
|
312
|
+
|
|
313
|
+
## Shared Resources
|
|
314
|
+
|
|
315
|
+
The client also exposes the standard E2B resources, including `Volume`,
|
|
316
|
+
`AsyncVolume`, `Template`, `AsyncTemplate`, `Secret`, and `AsyncSecret`:
|
|
317
|
+
|
|
318
|
+
```python
|
|
319
|
+
volume = client.Volume.create("my-volume")
|
|
320
|
+
template_exists = client.Template.exists("my-template")
|
|
321
|
+
secret = client.Secret.create("example-key", "example-value")
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
## Lifecycle
|
|
325
|
+
|
|
326
|
+
These snippets create sandboxes directly and explicitly call `kill()` when
|
|
327
|
+
finished. For long-lived workflows, save the sandbox ID and reconnect with the
|
|
328
|
+
matching `connect()` method shown above.
|
|
329
|
+
|
|
330
|
+
For more runnable Python examples, see [`examples/python/`](../../examples/python/).
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"""Airabox Python SDK."""
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
|
|
5
|
+
from .client import E2B, E2BClientParams
|
|
6
|
+
from .constants import (
|
|
7
|
+
DEFAULT_CODE_INTERPRETER_TEMPLATE,
|
|
8
|
+
DEFAULT_DESKTOP_TEMPLATE,
|
|
9
|
+
DEFAULT_MOBILE_TEMPLATE,
|
|
10
|
+
)
|
|
11
|
+
from .desktop import AsyncDesktopSandbox, AsyncVNCStream, DesktopSandbox, VNCStream
|
|
12
|
+
from .mobile import AsyncMobileSandbox, MobileSandbox
|
|
13
|
+
|
|
14
|
+
__all__ = [
|
|
15
|
+
"E2B",
|
|
16
|
+
"E2BClientParams",
|
|
17
|
+
"AsyncDesktopSandbox",
|
|
18
|
+
"AsyncMobileSandbox",
|
|
19
|
+
"AsyncVNCStream",
|
|
20
|
+
"DEFAULT_CODE_INTERPRETER_TEMPLATE",
|
|
21
|
+
"DEFAULT_DESKTOP_TEMPLATE",
|
|
22
|
+
"DEFAULT_MOBILE_TEMPLATE",
|
|
23
|
+
"DesktopSandbox",
|
|
24
|
+
"MobileSandbox",
|
|
25
|
+
"VNCStream",
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
os.environ.setdefault("E2B_DOMAIN", "e2b.airacloud.net")
|