dynamiq-sandboxes 0.2.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.
Files changed (34) hide show
  1. dynamiq_sandboxes-0.2.0/LICENSE +190 -0
  2. dynamiq_sandboxes-0.2.0/PKG-INFO +439 -0
  3. dynamiq_sandboxes-0.2.0/README.md +392 -0
  4. dynamiq_sandboxes-0.2.0/pyproject.toml +113 -0
  5. dynamiq_sandboxes-0.2.0/setup.cfg +4 -0
  6. dynamiq_sandboxes-0.2.0/src/dynamiq_sandboxes/__init__.py +106 -0
  7. dynamiq_sandboxes-0.2.0/src/dynamiq_sandboxes/async_sdk.py +2465 -0
  8. dynamiq_sandboxes-0.2.0/src/dynamiq_sandboxes/browser.py +1139 -0
  9. dynamiq_sandboxes-0.2.0/src/dynamiq_sandboxes/client/__init__.py +5 -0
  10. dynamiq_sandboxes-0.2.0/src/dynamiq_sandboxes/client/http.py +225 -0
  11. dynamiq_sandboxes-0.2.0/src/dynamiq_sandboxes/client/retry.py +51 -0
  12. dynamiq_sandboxes-0.2.0/src/dynamiq_sandboxes/client/timeout.py +32 -0
  13. dynamiq_sandboxes-0.2.0/src/dynamiq_sandboxes/desktop.py +250 -0
  14. dynamiq_sandboxes-0.2.0/src/dynamiq_sandboxes/exceptions.py +125 -0
  15. dynamiq_sandboxes-0.2.0/src/dynamiq_sandboxes/filesystem.py +427 -0
  16. dynamiq_sandboxes-0.2.0/src/dynamiq_sandboxes/interpreter.py +670 -0
  17. dynamiq_sandboxes-0.2.0/src/dynamiq_sandboxes/process.py +488 -0
  18. dynamiq_sandboxes-0.2.0/src/dynamiq_sandboxes/pty.py +764 -0
  19. dynamiq_sandboxes-0.2.0/src/dynamiq_sandboxes/py.typed +2 -0
  20. dynamiq_sandboxes-0.2.0/src/dynamiq_sandboxes/sandbox.py +581 -0
  21. dynamiq_sandboxes-0.2.0/src/dynamiq_sandboxes/snapshot.py +262 -0
  22. dynamiq_sandboxes-0.2.0/src/dynamiq_sandboxes/stream.py +664 -0
  23. dynamiq_sandboxes-0.2.0/src/dynamiq_sandboxes/volume.py +539 -0
  24. dynamiq_sandboxes-0.2.0/src/dynamiq_sandboxes.egg-info/PKG-INFO +439 -0
  25. dynamiq_sandboxes-0.2.0/src/dynamiq_sandboxes.egg-info/SOURCES.txt +32 -0
  26. dynamiq_sandboxes-0.2.0/src/dynamiq_sandboxes.egg-info/dependency_links.txt +1 -0
  27. dynamiq_sandboxes-0.2.0/src/dynamiq_sandboxes.egg-info/requires.txt +23 -0
  28. dynamiq_sandboxes-0.2.0/src/dynamiq_sandboxes.egg-info/top_level.txt +1 -0
  29. dynamiq_sandboxes-0.2.0/tests/test_browser.py +427 -0
  30. dynamiq_sandboxes-0.2.0/tests/test_client.py +525 -0
  31. dynamiq_sandboxes-0.2.0/tests/test_desktop.py +676 -0
  32. dynamiq_sandboxes-0.2.0/tests/test_errors.py +224 -0
  33. dynamiq_sandboxes-0.2.0/tests/test_retry.py +278 -0
  34. dynamiq_sandboxes-0.2.0/tests/test_sandbox.py +701 -0
@@ -0,0 +1,190 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to the Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright 2024-2025 Dynamiq AI Ltd.
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
@@ -0,0 +1,439 @@
1
+ Metadata-Version: 2.4
2
+ Name: dynamiq-sandboxes
3
+ Version: 0.2.0
4
+ Summary: Python SDK for Dynamiq Sandboxes - Secure code execution, browser automation, and virtual desktops
5
+ Author-email: Dynamiq <support@getdynamiq.ai>
6
+ Maintainer-email: Dynamiq <support@getdynamiq.ai>
7
+ License-Expression: Apache-2.0
8
+ Project-URL: Homepage, https://sandboxes.getdynamiq.ai
9
+ Project-URL: Documentation, https://sandboxes.getdynamiq.ai
10
+ Project-URL: Repository, https://github.com/dynamiq-ai/dynamiq
11
+ Project-URL: Bug Tracker, https://github.com/dynamiq-ai/dynamiq/issues
12
+ Keywords: sandbox,code-execution,browser-automation,virtual-desktop,ai-agents,dynamiq,e2b-alternative,daytona-alternative,code-interpreter,selenium-alternative
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Operating System :: OS Independent
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.9
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
22
+ Classifier: Topic :: Internet :: WWW/HTTP :: Browsers
23
+ Classifier: Topic :: System :: Emulators
24
+ Classifier: Typing :: Typed
25
+ Requires-Python: >=3.9
26
+ Description-Content-Type: text/markdown
27
+ License-File: LICENSE
28
+ Requires-Dist: httpx[http2]>=0.24.0
29
+ Requires-Dist: pydantic>=2.0.0
30
+ Requires-Dist: typing-extensions>=4.0.0; python_version < "3.10"
31
+ Provides-Extra: streaming
32
+ Requires-Dist: websocket-client>=1.6.0; extra == "streaming"
33
+ Requires-Dist: websockets>=11.0; extra == "streaming"
34
+ Provides-Extra: all
35
+ Requires-Dist: websocket-client>=1.6.0; extra == "all"
36
+ Requires-Dist: websockets>=11.0; extra == "all"
37
+ Provides-Extra: dev
38
+ Requires-Dist: pytest>=8.0; extra == "dev"
39
+ Requires-Dist: pytest-cov>=4.0; extra == "dev"
40
+ Requires-Dist: pytest-asyncio>=0.23; extra == "dev"
41
+ Requires-Dist: respx>=0.21; extra == "dev"
42
+ Requires-Dist: coverage>=7.0; extra == "dev"
43
+ Requires-Dist: black>=24.0; extra == "dev"
44
+ Requires-Dist: ruff>=0.1.0; extra == "dev"
45
+ Requires-Dist: mypy>=1.0; extra == "dev"
46
+ Dynamic: license-file
47
+
48
+ # Dynamiq Sandboxes
49
+
50
+ [![PyPI version](https://badge.fury.io/py/dynamiq-sandboxes.svg)](https://pypi.org/project/dynamiq-sandboxes/)
51
+ [![Python 3.9+](https://img.shields.io/badge/python-3.9+-blue.svg)](https://www.python.org/downloads/)
52
+ [![License: Apache 2.0](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
53
+
54
+ Python SDK for [Dynamiq Sandboxes](https://sandboxes.getdynamiq.ai) — secure, isolated environments for code execution, browser automation, and virtual desktops.
55
+
56
+ Built for AI agents and automation pipelines. Part of the [Dynamiq](https://github.com/dynamiq-ai/dynamiq) ecosystem.
57
+
58
+ ## Installation
59
+
60
+ ```bash
61
+ pip install dynamiq-sandboxes
62
+ ```
63
+
64
+ ## Quick Start
65
+
66
+ ```bash
67
+ export DYNAMIQ_API_KEY="your-api-key"
68
+ ```
69
+
70
+ ```python
71
+ from dynamiq_sandboxes import Sandbox
72
+
73
+ sandbox = Sandbox.create(template="python")
74
+
75
+ result = sandbox.execute_command("echo 'Hello from the sandbox!'")
76
+ print(result["stdout"]) # Hello from the sandbox!
77
+
78
+ sandbox.close()
79
+ ```
80
+
81
+ ## Code Sandboxes
82
+
83
+ Isolated execution environments with Python, Node.js, and shell support.
84
+
85
+ ```python
86
+ from dynamiq_sandboxes import Sandbox
87
+
88
+ sandbox = Sandbox.create(template="python", timeout=3600)
89
+
90
+ # Execute shell commands (auto-wrapped in /bin/bash, like E2B)
91
+ result = sandbox.execute_command("echo hello && ls /")
92
+ print(result["stdout"])
93
+ print(result["exit_code"]) # 0
94
+
95
+ # Run Python code directly
96
+ output = sandbox.run_code("print(2 + 2)", language="python")
97
+ print(output["stdout"]) # 4
98
+
99
+ # Explicit args mode (no shell wrapping)
100
+ result = sandbox.execute_command("python3", args=["-c", "print('direct')"])
101
+
102
+ # File operations
103
+ sandbox.filesystem.write("/app/config.json", '{"key": "value"}')
104
+ content = sandbox.filesystem.read("/app/config.json")
105
+ print(content) # {"key": "value"}
106
+
107
+ files = sandbox.filesystem.list("/app")
108
+ for f in files:
109
+ print(f"{f.name} {f.size}B ({f.type})")
110
+
111
+ # Directory operations
112
+ sandbox.filesystem.mkdir("/app/data")
113
+ sandbox.filesystem.copy("/app/config.json", "/app/data/config.json")
114
+ sandbox.filesystem.move("/app/data/config.json", "/app/data/settings.json")
115
+ sandbox.filesystem.remove("/app/data", recursive=True)
116
+
117
+ # Upload / download files
118
+ sandbox.filesystem.upload("local_file.py", "/app/script.py")
119
+ sandbox.filesystem.download("/app/output.csv", "local_output.csv")
120
+
121
+ # Check file existence and metadata
122
+ if sandbox.filesystem.exists("/app/script.py"):
123
+ info = sandbox.filesystem.stat("/app/script.py")
124
+ print(f"{info.name}: {info.size} bytes")
125
+
126
+ # Resource metrics
127
+ metrics = sandbox.metrics()
128
+ print(f"CPU: {metrics['cpu']['usage_percent']}%")
129
+
130
+ # Extend session timeout
131
+ sandbox.extend_timeout(3600) # Add 1 hour
132
+
133
+ sandbox.close()
134
+ ```
135
+
136
+ ## Browser Automation
137
+
138
+ Headless Chromium with CDP access, screenshots, scraping, and live streaming.
139
+
140
+ ```python
141
+ from dynamiq_sandboxes import Browser
142
+
143
+ browser = Browser.create(
144
+ stealth=True, # Anti-detection mode
145
+ viewport_width=1920,
146
+ viewport_height=1080,
147
+ )
148
+
149
+ # Navigate to pages
150
+ browser.navigate("https://example.com")
151
+
152
+ # Take screenshots
153
+ result = browser.screenshot(full_page=True)
154
+ # result["image"] is a data URI: data:image/png;base64,...
155
+ # result["width"], result["height"]
156
+
157
+ # Scrape page content
158
+ scrape = browser.scrape(format="text")
159
+ print(scrape["content"])
160
+
161
+ # Execute JavaScript
162
+ title = browser.execute_script("() => document.title")
163
+ url = browser.execute_script("() => window.location.href")
164
+
165
+ # Navigation history
166
+ browser.go_back()
167
+ browser.go_forward()
168
+ browser.reload()
169
+
170
+ # Browser context (cookies, localStorage)
171
+ ctx = browser.get_context()
172
+ print(ctx)
173
+
174
+ # Console logs and network requests
175
+ logs = browser.get_logs()
176
+ requests = browser.get_network_requests()
177
+ har = browser.export_har()
178
+
179
+ # Live streaming info (for embedding in UI)
180
+ live = browser.get_live_view()
181
+ print(live["stream_url"]) # WebSocket stream URL
182
+ print(live["livekit_url"]) # LiveKit WebRTC URL
183
+ print(live["livekit_token"]) # JWT token for viewer
184
+
185
+ browser.close()
186
+ ```
187
+
188
+ ### CDP Access (Playwright / Puppeteer)
189
+
190
+ Every browser session exposes a **Chrome DevTools Protocol** WebSocket that works with any CDP-compatible tool:
191
+
192
+ ```python
193
+ # Get the CDP URL from the sandbox
194
+ browser = Browser.create(stealth=True)
195
+ cdp_url = browser.data["cdp_websocket_url"]
196
+ # wss://api.sandboxes.getdynamiq.ai/v1/browser/sessions/{id}/cdp
197
+ ```
198
+
199
+ **Playwright (Python):**
200
+
201
+ ```python
202
+ from playwright.async_api import async_playwright
203
+
204
+ async with async_playwright() as p:
205
+ b = await p.chromium.connect_over_cdp(
206
+ cdp_url,
207
+ headers={"X-API-Key": "your-api-key"},
208
+ )
209
+ page = b.contexts[0].pages[0]
210
+
211
+ await page.goto("https://example.com")
212
+ print(await page.title())
213
+ await page.screenshot(path="screenshot.png")
214
+ ```
215
+
216
+ **Puppeteer (Node.js):**
217
+
218
+ ```javascript
219
+ const browser = await puppeteer.connect({
220
+ browserWSEndpoint: cdpUrl,
221
+ headers: { "X-API-Key": "your-api-key" },
222
+ });
223
+ const page = (await browser.pages())[0];
224
+ await page.goto("https://example.com");
225
+ await page.screenshot({ path: "screenshot.png" });
226
+ ```
227
+
228
+ ## Virtual Desktops
229
+
230
+ Full Ubuntu desktop with XFCE, mouse/keyboard control, and VNC streaming.
231
+
232
+ ```python
233
+ from dynamiq_sandboxes import Desktop
234
+
235
+ desktop = Desktop.create(template="ubuntu-desktop")
236
+
237
+ # Take screenshots
238
+ result = desktop.screenshot()
239
+ # result["image"] is a data URI, result["width"], result["height"]
240
+
241
+ # Launch applications
242
+ desktop.launch(application="xfce4-terminal")
243
+ desktop.launch(application="firefox")
244
+
245
+ # Mouse control
246
+ desktop.mouse_click(x=500, y=300)
247
+ desktop.mouse_click(x=500, y=300, button="right") # Right click
248
+ desktop.mouse_click(x=500, y=300, double_click=True) # Double click
249
+ desktop.mouse_move(x=100, y=200)
250
+ desktop.mouse_scroll(x=500, y=300, delta_x=0, delta_y=-3)
251
+ desktop.mouse_drag(start_x=100, start_y=100, end_x=300, end_y=300)
252
+
253
+ # Keyboard input
254
+ desktop.keyboard_type(text="Hello, World!")
255
+ desktop.keyboard_press(keys=["Return"])
256
+ desktop.keyboard_press(keys=["ctrl", "c"]) # Hotkey combo
257
+ desktop.keyboard_press(keys=["ctrl", "l"]) # Clear terminal
258
+
259
+ # Open URLs
260
+ desktop.open(path="https://example.com")
261
+
262
+ # Get cursor position
263
+ cursor = desktop.cursor()
264
+ print(f"Cursor at ({cursor['x']}, {cursor['y']})")
265
+
266
+ # VNC streaming (for embedding in your UI)
267
+ stream = desktop.stream_start()
268
+ info = desktop.stream_info()
269
+ print(f"noVNC URL: {info.get('novnc_url')}")
270
+ print(f"WebSocket: {info.get('stream_url')}")
271
+
272
+ desktop.close()
273
+ ```
274
+
275
+ ## REST API
276
+
277
+ All SDK methods map to REST API calls:
278
+
279
+ ```bash
280
+ # Create a sandbox
281
+ curl -X POST https://api.sandboxes.getdynamiq.ai/v1/sandboxes \
282
+ -H "X-API-Key: YOUR_API_KEY" \
283
+ -H "Content-Type: application/json" \
284
+ -d '{"template_id": "python", "timeout": 3600}'
285
+
286
+ # Execute a command
287
+ curl -X POST https://api.sandboxes.getdynamiq.ai/v1/sandboxes/{id}/commands \
288
+ -H "X-API-Key: YOUR_API_KEY" \
289
+ -H "Content-Type: application/json" \
290
+ -d '{"command": "echo hello"}'
291
+
292
+ # Create a browser session
293
+ curl -X POST https://api.sandboxes.getdynamiq.ai/v1/browser/sessions \
294
+ -H "X-API-Key: YOUR_API_KEY" \
295
+ -H "Content-Type: application/json" \
296
+ -d '{"stealth": true}'
297
+
298
+ # Create a desktop
299
+ curl -X POST https://api.sandboxes.getdynamiq.ai/v1/sandboxes \
300
+ -H "X-API-Key: YOUR_API_KEY" \
301
+ -H "Content-Type: application/json" \
302
+ -d '{"template_id": "ubuntu-desktop", "sandbox_type": "desktop"}'
303
+ ```
304
+
305
+ ## Configuration
306
+
307
+ | Environment Variable | Description | Default |
308
+ |---------------------|-------------|---------|
309
+ | `DYNAMIQ_API_KEY` | API key for authentication | Required |
310
+ | `DYNAMIQ_API_URL` | API base URL | `https://api.sandboxes.getdynamiq.ai/v1` |
311
+
312
+ ```python
313
+ # Or pass directly
314
+ sandbox = Sandbox.create(
315
+ template="python",
316
+ api_key="your-api-key",
317
+ base_url="https://api.sandboxes.getdynamiq.ai/v1",
318
+ )
319
+ ```
320
+
321
+ ## API Reference
322
+
323
+ ### Sandbox
324
+
325
+ | Method | Description |
326
+ |--------|-------------|
327
+ | `Sandbox.create(template, timeout, vcpu, memory_mb, ...)` | Create a new sandbox |
328
+ | `Sandbox.get(sandbox_id)` | Connect to existing sandbox |
329
+ | `sandbox.execute_command(command, args, working_dir, timeout)` | Execute a shell command |
330
+ | `sandbox.run_code(code, language, timeout)` | Run code in a language interpreter |
331
+ | `sandbox.filesystem.write(path, content)` | Write a file |
332
+ | `sandbox.filesystem.read(path)` | Read a file |
333
+ | `sandbox.filesystem.list(path)` | List directory contents |
334
+ | `sandbox.filesystem.mkdir(path)` | Create directory |
335
+ | `sandbox.filesystem.remove(path, recursive)` | Delete file or directory |
336
+ | `sandbox.filesystem.exists(path)` | Check if path exists |
337
+ | `sandbox.filesystem.stat(path)` | Get file metadata |
338
+ | `sandbox.filesystem.copy(src, dst)` | Copy file/directory |
339
+ | `sandbox.filesystem.move(src, dst)` | Move/rename file |
340
+ | `sandbox.filesystem.upload(local, remote)` | Upload local file |
341
+ | `sandbox.filesystem.download(remote, local)` | Download file |
342
+ | `sandbox.metrics()` | Get CPU/memory/disk metrics |
343
+ | `sandbox.extend_timeout(seconds)` | Extend session lifetime |
344
+ | `sandbox.refresh()` | Refresh sandbox state |
345
+ | `sandbox.close()` | Terminate sandbox |
346
+
347
+ ### Browser
348
+
349
+ | Method | Description |
350
+ |--------|-------------|
351
+ | `Browser.create(stealth, viewport_width, viewport_height, ...)` | Create browser session |
352
+ | `Browser.get(session_id)` | Connect to existing session |
353
+ | `browser.navigate(url, wait_until, timeout)` | Navigate to URL |
354
+ | `browser.screenshot(format, full_page, quality)` | Capture screenshot |
355
+ | `browser.scrape(format, wait_for, timeout)` | Extract page content |
356
+ | `browser.execute_script(script)` | Execute JavaScript |
357
+ | `browser.go_back()` | Navigate back |
358
+ | `browser.go_forward()` | Navigate forward |
359
+ | `browser.reload()` | Reload page |
360
+ | `browser.get_current_url()` | Get current URL |
361
+ | `browser.get_context()` | Get cookies/storage |
362
+ | `browser.get_logs()` | Get console logs |
363
+ | `browser.get_network_requests()` | Get captured requests |
364
+ | `browser.export_har()` | Export HAR archive |
365
+ | `browser.get_live_view()` | Get streaming info |
366
+ | `browser.send_input(type, x, y, text, ...)` | Send input events |
367
+ | `browser.close()` | Close session |
368
+
369
+ ### Desktop
370
+
371
+ | Method | Description |
372
+ |--------|-------------|
373
+ | `Desktop.create(template, timeout, ...)` | Create virtual desktop |
374
+ | `Desktop.get(desktop_id)` | Connect to existing desktop |
375
+ | `desktop.screenshot(format, quality)` | Capture screenshot |
376
+ | `desktop.launch(application, args)` | Launch application |
377
+ | `desktop.mouse_click(x, y, button, double_click)` | Mouse click |
378
+ | `desktop.mouse_move(x, y)` | Move cursor |
379
+ | `desktop.mouse_scroll(x, y, delta_x, delta_y)` | Scroll |
380
+ | `desktop.mouse_drag(start_x, start_y, end_x, end_y)` | Drag |
381
+ | `desktop.keyboard_type(text)` | Type text |
382
+ | `desktop.keyboard_press(keys, duration_ms)` | Press keys |
383
+ | `desktop.cursor()` | Get cursor position |
384
+ | `desktop.open(path)` | Open file/URL |
385
+ | `desktop.stream_start()` | Start VNC stream |
386
+ | `desktop.stream_stop()` | Stop VNC stream |
387
+ | `desktop.stream_info()` | Get stream status |
388
+ | `desktop.list_windows()` | List windows |
389
+ | `desktop.close()` | Close desktop |
390
+
391
+ ## Error Handling
392
+
393
+ ```python
394
+ from dynamiq_sandboxes import (
395
+ Sandbox, APIError, AuthenticationError,
396
+ NotFoundError, RateLimitError, TimeoutError,
397
+ )
398
+
399
+ try:
400
+ sandbox = Sandbox.create(template="python")
401
+ result = sandbox.execute_command("echo hello")
402
+ except AuthenticationError:
403
+ print("Invalid API key")
404
+ except RateLimitError:
405
+ print("Rate limited, retry later")
406
+ except TimeoutError:
407
+ print("Request timed out")
408
+ except APIError as e:
409
+ print(f"API error: {e}")
410
+ ```
411
+
412
+ ## Use with Dynamiq Agents
413
+
414
+ Dynamiq Sandboxes integrates with the [Dynamiq](https://github.com/dynamiq-ai/dynamiq) orchestration framework for building AI agents:
415
+
416
+ ```python
417
+ from dynamiq.nodes.tools.e2b_sandbox import E2BInterpreterTool
418
+ from dynamiq.connections import E2B as E2BConnection
419
+
420
+ # Use Dynamiq Sandboxes as a tool for AI agents
421
+ tool = E2BInterpreterTool(
422
+ connection=E2BConnection(api_key="your-dynamiq-sandbox-key")
423
+ )
424
+ ```
425
+
426
+ ## Requirements
427
+
428
+ - Python 3.9+
429
+ - An active [Dynamiq](https://sandboxes.getdynamiq.ai) account
430
+
431
+ ## Links
432
+
433
+ - **Dashboard**: [sandboxes.getdynamiq.ai](https://sandboxes.getdynamiq.ai)
434
+ - **Dynamiq Framework**: [github.com/dynamiq-ai/dynamiq](https://github.com/dynamiq-ai/dynamiq)
435
+ - **Issues**: [GitHub Issues](https://github.com/dynamiq-ai/dynamiq/issues)
436
+
437
+ ## License
438
+
439
+ Apache 2.0