miosa-sandbox 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.
- miosa_sandbox-0.1.0/.gitignore +22 -0
- miosa_sandbox-0.1.0/LICENSE +21 -0
- miosa_sandbox-0.1.0/PKG-INFO +229 -0
- miosa_sandbox-0.1.0/README.md +197 -0
- miosa_sandbox-0.1.0/pyproject.toml +110 -0
- miosa_sandbox-0.1.0/src/miosa_sandbox/__init__.py +129 -0
- miosa_sandbox-0.1.0/src/miosa_sandbox/client.py +393 -0
- miosa_sandbox-0.1.0/src/miosa_sandbox/computer.py +970 -0
- miosa_sandbox-0.1.0/src/miosa_sandbox/computer_client.py +170 -0
- miosa_sandbox-0.1.0/src/miosa_sandbox/errors.py +217 -0
- miosa_sandbox-0.1.0/src/miosa_sandbox/http.py +369 -0
- miosa_sandbox-0.1.0/src/miosa_sandbox/py.typed +0 -0
- miosa_sandbox-0.1.0/src/miosa_sandbox/sandbox.py +669 -0
- miosa_sandbox-0.1.0/src/miosa_sandbox/sse.py +211 -0
- miosa_sandbox-0.1.0/src/miosa_sandbox/types.py +274 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Build / packaging
|
|
2
|
+
build/
|
|
3
|
+
dist/
|
|
4
|
+
*.egg-info/
|
|
5
|
+
*.egg
|
|
6
|
+
|
|
7
|
+
# Caches
|
|
8
|
+
.pytest_cache/
|
|
9
|
+
.mypy_cache/
|
|
10
|
+
.ruff_cache/
|
|
11
|
+
__pycache__/
|
|
12
|
+
*.pyc
|
|
13
|
+
|
|
14
|
+
# Virtual envs
|
|
15
|
+
.venv/
|
|
16
|
+
venv/
|
|
17
|
+
env/
|
|
18
|
+
|
|
19
|
+
# Editor
|
|
20
|
+
.idea/
|
|
21
|
+
.vscode/
|
|
22
|
+
.DS_Store
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 MIOSA
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: miosa-sandbox
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: DEPRECATED — use `miosa` instead
|
|
5
|
+
Project-URL: Homepage, https://miosa.ai
|
|
6
|
+
Project-URL: Documentation, https://docs.miosa.ai/sdk/python
|
|
7
|
+
Project-URL: Repository, https://github.com/miosa-ai/miosa
|
|
8
|
+
Project-URL: Issues, https://github.com/miosa-ai/miosa/issues
|
|
9
|
+
Author-email: MIOSA <dev@miosa.ai>
|
|
10
|
+
License-Expression: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: agents,ai,code-execution,miosa,sandbox,sdk
|
|
13
|
+
Classifier: Development Status :: 7 - Inactive
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
22
|
+
Classifier: Typing :: Typed
|
|
23
|
+
Requires-Python: >=3.10
|
|
24
|
+
Requires-Dist: httpx>=0.27
|
|
25
|
+
Provides-Extra: dev
|
|
26
|
+
Requires-Dist: mypy>=1.10; extra == 'dev'
|
|
27
|
+
Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
|
|
28
|
+
Requires-Dist: pytest-httpx>=0.30; extra == 'dev'
|
|
29
|
+
Requires-Dist: pytest>=8; extra == 'dev'
|
|
30
|
+
Requires-Dist: ruff>=0.5; extra == 'dev'
|
|
31
|
+
Description-Content-Type: text/markdown
|
|
32
|
+
|
|
33
|
+
# miosa-sandbox
|
|
34
|
+
|
|
35
|
+
> ## ⚠️ Deprecated
|
|
36
|
+
> This package has been folded into the main MIOSA SDK. Migrate to:
|
|
37
|
+
> - **Python:** `pip install miosa` → `from miosa import Miosa; client = Miosa(api_key="msk_..."); sandbox = client.sandboxes.create(...)`
|
|
38
|
+
> - **TypeScript:** `npm install @miosa/sdk` → `import { Miosa } from "@miosa/sdk";`
|
|
39
|
+
> - **Go:** `go get github.com/miosa-ai/miosa-go` → `client := miosa.NewClient("msk_...")`
|
|
40
|
+
>
|
|
41
|
+
> See [Migrating from miosa-sandbox](https://miosa.ai/docs/migrating-from-miosa-sandbox/) for full migration guide.
|
|
42
|
+
>
|
|
43
|
+
> The `miosa-sandbox` package will receive bug fixes for 6 months but no new features. Sunset date: 2026-11-08.
|
|
44
|
+
|
|
45
|
+
Python SDK for the [MIOSA](https://miosa.ai) Sandbox API.
|
|
46
|
+
|
|
47
|
+
New work should use `miosa`, where sandboxes are persistent agent workspaces by
|
|
48
|
+
default: create or resume by name, write files under `/workspace`, run
|
|
49
|
+
installs/tests/builds inside the sandbox, expose previews, snapshot/pause
|
|
50
|
+
between sessions, and publish from the sandbox.
|
|
51
|
+
|
|
52
|
+
## Install
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
pip install miosa-sandbox
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Requires Python 3.10+. The only runtime dependency is `httpx`.
|
|
59
|
+
|
|
60
|
+
## Quickstart
|
|
61
|
+
|
|
62
|
+
```python
|
|
63
|
+
from miosa_sandbox import MIOSA
|
|
64
|
+
|
|
65
|
+
client = MIOSA(api_key="mki_...")
|
|
66
|
+
sb = client.sandboxes.create(
|
|
67
|
+
image="miosa-sandbox",
|
|
68
|
+
timeout_sec=86_400,
|
|
69
|
+
idle_timeout_sec=1_800,
|
|
70
|
+
)
|
|
71
|
+
result = sb.exec("python3 -c 'print(1 + 1)'")
|
|
72
|
+
print(result.stdout) # "2\n"
|
|
73
|
+
sb.write_file("/workspace/foo.txt", "hello")
|
|
74
|
+
print(sb.read_file("/workspace/foo.txt")) # "hello"
|
|
75
|
+
print(sb.snapshots.create("after-hello-world"))
|
|
76
|
+
sb.pause()
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Or with the context manager so cleanup happens even when something throws:
|
|
80
|
+
|
|
81
|
+
```python
|
|
82
|
+
with MIOSA(api_key="mki_...") as client, \
|
|
83
|
+
client.sandboxes.create(image="debian-12-sandbox-v8") as sb:
|
|
84
|
+
result = sb.exec("echo hello")
|
|
85
|
+
print(result.stdout) # "hello\n"
|
|
86
|
+
# sandbox destroyed and HTTP client closed automatically
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Async
|
|
90
|
+
|
|
91
|
+
For agents and servers, use `AsyncMIOSA`:
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
import asyncio
|
|
95
|
+
from miosa_sandbox import AsyncMIOSA
|
|
96
|
+
|
|
97
|
+
async def main():
|
|
98
|
+
async with AsyncMIOSA(api_key="mki_...") as client:
|
|
99
|
+
sb = await client.sandboxes.create(image="debian-12-sandbox-v8")
|
|
100
|
+
try:
|
|
101
|
+
result = await sb.exec("python3 -c 'print(40 + 2)'")
|
|
102
|
+
print(result.stdout.strip()) # "42"
|
|
103
|
+
finally:
|
|
104
|
+
await sb.destroy()
|
|
105
|
+
|
|
106
|
+
asyncio.run(main())
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## Auth
|
|
110
|
+
|
|
111
|
+
Get an API key from
|
|
112
|
+
[app.miosa.ai/settings/api-keys](https://app.miosa.ai/settings/api-keys).
|
|
113
|
+
Keys begin with `mki_` (user) or `msk_` (service / CI).
|
|
114
|
+
|
|
115
|
+
```python
|
|
116
|
+
import os
|
|
117
|
+
from miosa_sandbox import MIOSA
|
|
118
|
+
|
|
119
|
+
client = MIOSA(api_key=os.environ["MIOSA_API_KEY"])
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
Keep keys out of source control — use environment variables or a secrets
|
|
123
|
+
manager.
|
|
124
|
+
|
|
125
|
+
## Common patterns
|
|
126
|
+
|
|
127
|
+
### Execute a command
|
|
128
|
+
|
|
129
|
+
```python
|
|
130
|
+
result = sb.exec("python3 script.py", opts={"timeout_sec": 60})
|
|
131
|
+
if result.exit_code != 0:
|
|
132
|
+
raise RuntimeError(result.stderr)
|
|
133
|
+
print(result.stdout)
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### Stream command output
|
|
137
|
+
|
|
138
|
+
```python
|
|
139
|
+
for chunk in sb.exec_stream("python3 long_script.py"):
|
|
140
|
+
if chunk.stream == "stdout":
|
|
141
|
+
print(chunk.data.decode(), end="")
|
|
142
|
+
elif chunk.stream == "stderr":
|
|
143
|
+
import sys
|
|
144
|
+
sys.stderr.write(chunk.data.decode())
|
|
145
|
+
elif chunk.stream == "exit":
|
|
146
|
+
print(f"\n[exit {chunk.exit_code}]")
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### Upload / download files
|
|
150
|
+
|
|
151
|
+
```python
|
|
152
|
+
from pathlib import Path
|
|
153
|
+
|
|
154
|
+
# bytes, str, or pathlib.Path all accepted
|
|
155
|
+
sb.upload("/workspace/script.py", "print('hello')")
|
|
156
|
+
sb.upload("/workspace/data.bin", b"\x00\x01\x02")
|
|
157
|
+
sb.upload("/workspace/local.txt", Path("local.txt"))
|
|
158
|
+
|
|
159
|
+
# Bytes back out
|
|
160
|
+
data: bytes = sb.download("/workspace/output.json")
|
|
161
|
+
import json
|
|
162
|
+
print(json.loads(data))
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### Subscribe to lifecycle events (async)
|
|
166
|
+
|
|
167
|
+
```python
|
|
168
|
+
async for event in sb.events():
|
|
169
|
+
if event.type == "state_changed":
|
|
170
|
+
print("new state:", event.data["state"])
|
|
171
|
+
elif event.type == "exec_output":
|
|
172
|
+
print(event.data["stream"], event.data["data"])
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
The stream auto-closes when the sandbox reaches `destroyed`.
|
|
176
|
+
|
|
177
|
+
## Error handling
|
|
178
|
+
|
|
179
|
+
All SDK errors inherit from `MiosaError` and carry `status_code`, `code`,
|
|
180
|
+
and an optional `request_id` for support.
|
|
181
|
+
|
|
182
|
+
```python
|
|
183
|
+
from miosa_sandbox import (
|
|
184
|
+
MiosaError,
|
|
185
|
+
MiosaAuthError,
|
|
186
|
+
MiosaNotFoundError,
|
|
187
|
+
MiosaRateLimitError,
|
|
188
|
+
MiosaTimeoutError,
|
|
189
|
+
)
|
|
190
|
+
|
|
191
|
+
try:
|
|
192
|
+
sb = client.sandboxes.get(some_id)
|
|
193
|
+
except MiosaAuthError:
|
|
194
|
+
print("Check your API key")
|
|
195
|
+
except MiosaNotFoundError:
|
|
196
|
+
print("Sandbox not found")
|
|
197
|
+
except MiosaRateLimitError as err:
|
|
198
|
+
print(f"Rate limited — retry after {err.retry_after}s")
|
|
199
|
+
except MiosaTimeoutError:
|
|
200
|
+
print("Request timed out")
|
|
201
|
+
except MiosaError as err:
|
|
202
|
+
print(f"[{err.code}] {err} (request: {err.request_id})")
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
## Client options
|
|
206
|
+
|
|
207
|
+
```python
|
|
208
|
+
client = MIOSA(
|
|
209
|
+
api_key="mki_...", # required
|
|
210
|
+
base_url="https://api.miosa.ai/api/v1", # default
|
|
211
|
+
timeout=30.0, # seconds, default 30
|
|
212
|
+
max_retries=3, # 429/5xx retries, default 3
|
|
213
|
+
)
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
## Available templates
|
|
217
|
+
|
|
218
|
+
| Template | Description |
|
|
219
|
+
| -------- | ----------- |
|
|
220
|
+
| `miosa-sandbox` | Stable production alias for the current sandbox image. |
|
|
221
|
+
| `debian-12-sandbox-v8` | Debian Bookworm/glibc image with Python, Node, Elixir/Erlang, Go, Rust, Ruby, Java, Postgres, Redis, SQLite, Chromium, and Playwright support. |
|
|
222
|
+
|
|
223
|
+
## Docs
|
|
224
|
+
|
|
225
|
+
Full reference: <https://docs.miosa.ai/sdk/python>.
|
|
226
|
+
|
|
227
|
+
## License
|
|
228
|
+
|
|
229
|
+
MIT
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
# miosa-sandbox
|
|
2
|
+
|
|
3
|
+
> ## ⚠️ Deprecated
|
|
4
|
+
> This package has been folded into the main MIOSA SDK. Migrate to:
|
|
5
|
+
> - **Python:** `pip install miosa` → `from miosa import Miosa; client = Miosa(api_key="msk_..."); sandbox = client.sandboxes.create(...)`
|
|
6
|
+
> - **TypeScript:** `npm install @miosa/sdk` → `import { Miosa } from "@miosa/sdk";`
|
|
7
|
+
> - **Go:** `go get github.com/miosa-ai/miosa-go` → `client := miosa.NewClient("msk_...")`
|
|
8
|
+
>
|
|
9
|
+
> See [Migrating from miosa-sandbox](https://miosa.ai/docs/migrating-from-miosa-sandbox/) for full migration guide.
|
|
10
|
+
>
|
|
11
|
+
> The `miosa-sandbox` package will receive bug fixes for 6 months but no new features. Sunset date: 2026-11-08.
|
|
12
|
+
|
|
13
|
+
Python SDK for the [MIOSA](https://miosa.ai) Sandbox API.
|
|
14
|
+
|
|
15
|
+
New work should use `miosa`, where sandboxes are persistent agent workspaces by
|
|
16
|
+
default: create or resume by name, write files under `/workspace`, run
|
|
17
|
+
installs/tests/builds inside the sandbox, expose previews, snapshot/pause
|
|
18
|
+
between sessions, and publish from the sandbox.
|
|
19
|
+
|
|
20
|
+
## Install
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
pip install miosa-sandbox
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Requires Python 3.10+. The only runtime dependency is `httpx`.
|
|
27
|
+
|
|
28
|
+
## Quickstart
|
|
29
|
+
|
|
30
|
+
```python
|
|
31
|
+
from miosa_sandbox import MIOSA
|
|
32
|
+
|
|
33
|
+
client = MIOSA(api_key="mki_...")
|
|
34
|
+
sb = client.sandboxes.create(
|
|
35
|
+
image="miosa-sandbox",
|
|
36
|
+
timeout_sec=86_400,
|
|
37
|
+
idle_timeout_sec=1_800,
|
|
38
|
+
)
|
|
39
|
+
result = sb.exec("python3 -c 'print(1 + 1)'")
|
|
40
|
+
print(result.stdout) # "2\n"
|
|
41
|
+
sb.write_file("/workspace/foo.txt", "hello")
|
|
42
|
+
print(sb.read_file("/workspace/foo.txt")) # "hello"
|
|
43
|
+
print(sb.snapshots.create("after-hello-world"))
|
|
44
|
+
sb.pause()
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Or with the context manager so cleanup happens even when something throws:
|
|
48
|
+
|
|
49
|
+
```python
|
|
50
|
+
with MIOSA(api_key="mki_...") as client, \
|
|
51
|
+
client.sandboxes.create(image="debian-12-sandbox-v8") as sb:
|
|
52
|
+
result = sb.exec("echo hello")
|
|
53
|
+
print(result.stdout) # "hello\n"
|
|
54
|
+
# sandbox destroyed and HTTP client closed automatically
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Async
|
|
58
|
+
|
|
59
|
+
For agents and servers, use `AsyncMIOSA`:
|
|
60
|
+
|
|
61
|
+
```python
|
|
62
|
+
import asyncio
|
|
63
|
+
from miosa_sandbox import AsyncMIOSA
|
|
64
|
+
|
|
65
|
+
async def main():
|
|
66
|
+
async with AsyncMIOSA(api_key="mki_...") as client:
|
|
67
|
+
sb = await client.sandboxes.create(image="debian-12-sandbox-v8")
|
|
68
|
+
try:
|
|
69
|
+
result = await sb.exec("python3 -c 'print(40 + 2)'")
|
|
70
|
+
print(result.stdout.strip()) # "42"
|
|
71
|
+
finally:
|
|
72
|
+
await sb.destroy()
|
|
73
|
+
|
|
74
|
+
asyncio.run(main())
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Auth
|
|
78
|
+
|
|
79
|
+
Get an API key from
|
|
80
|
+
[app.miosa.ai/settings/api-keys](https://app.miosa.ai/settings/api-keys).
|
|
81
|
+
Keys begin with `mki_` (user) or `msk_` (service / CI).
|
|
82
|
+
|
|
83
|
+
```python
|
|
84
|
+
import os
|
|
85
|
+
from miosa_sandbox import MIOSA
|
|
86
|
+
|
|
87
|
+
client = MIOSA(api_key=os.environ["MIOSA_API_KEY"])
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Keep keys out of source control — use environment variables or a secrets
|
|
91
|
+
manager.
|
|
92
|
+
|
|
93
|
+
## Common patterns
|
|
94
|
+
|
|
95
|
+
### Execute a command
|
|
96
|
+
|
|
97
|
+
```python
|
|
98
|
+
result = sb.exec("python3 script.py", opts={"timeout_sec": 60})
|
|
99
|
+
if result.exit_code != 0:
|
|
100
|
+
raise RuntimeError(result.stderr)
|
|
101
|
+
print(result.stdout)
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### Stream command output
|
|
105
|
+
|
|
106
|
+
```python
|
|
107
|
+
for chunk in sb.exec_stream("python3 long_script.py"):
|
|
108
|
+
if chunk.stream == "stdout":
|
|
109
|
+
print(chunk.data.decode(), end="")
|
|
110
|
+
elif chunk.stream == "stderr":
|
|
111
|
+
import sys
|
|
112
|
+
sys.stderr.write(chunk.data.decode())
|
|
113
|
+
elif chunk.stream == "exit":
|
|
114
|
+
print(f"\n[exit {chunk.exit_code}]")
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### Upload / download files
|
|
118
|
+
|
|
119
|
+
```python
|
|
120
|
+
from pathlib import Path
|
|
121
|
+
|
|
122
|
+
# bytes, str, or pathlib.Path all accepted
|
|
123
|
+
sb.upload("/workspace/script.py", "print('hello')")
|
|
124
|
+
sb.upload("/workspace/data.bin", b"\x00\x01\x02")
|
|
125
|
+
sb.upload("/workspace/local.txt", Path("local.txt"))
|
|
126
|
+
|
|
127
|
+
# Bytes back out
|
|
128
|
+
data: bytes = sb.download("/workspace/output.json")
|
|
129
|
+
import json
|
|
130
|
+
print(json.loads(data))
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### Subscribe to lifecycle events (async)
|
|
134
|
+
|
|
135
|
+
```python
|
|
136
|
+
async for event in sb.events():
|
|
137
|
+
if event.type == "state_changed":
|
|
138
|
+
print("new state:", event.data["state"])
|
|
139
|
+
elif event.type == "exec_output":
|
|
140
|
+
print(event.data["stream"], event.data["data"])
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
The stream auto-closes when the sandbox reaches `destroyed`.
|
|
144
|
+
|
|
145
|
+
## Error handling
|
|
146
|
+
|
|
147
|
+
All SDK errors inherit from `MiosaError` and carry `status_code`, `code`,
|
|
148
|
+
and an optional `request_id` for support.
|
|
149
|
+
|
|
150
|
+
```python
|
|
151
|
+
from miosa_sandbox import (
|
|
152
|
+
MiosaError,
|
|
153
|
+
MiosaAuthError,
|
|
154
|
+
MiosaNotFoundError,
|
|
155
|
+
MiosaRateLimitError,
|
|
156
|
+
MiosaTimeoutError,
|
|
157
|
+
)
|
|
158
|
+
|
|
159
|
+
try:
|
|
160
|
+
sb = client.sandboxes.get(some_id)
|
|
161
|
+
except MiosaAuthError:
|
|
162
|
+
print("Check your API key")
|
|
163
|
+
except MiosaNotFoundError:
|
|
164
|
+
print("Sandbox not found")
|
|
165
|
+
except MiosaRateLimitError as err:
|
|
166
|
+
print(f"Rate limited — retry after {err.retry_after}s")
|
|
167
|
+
except MiosaTimeoutError:
|
|
168
|
+
print("Request timed out")
|
|
169
|
+
except MiosaError as err:
|
|
170
|
+
print(f"[{err.code}] {err} (request: {err.request_id})")
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
## Client options
|
|
174
|
+
|
|
175
|
+
```python
|
|
176
|
+
client = MIOSA(
|
|
177
|
+
api_key="mki_...", # required
|
|
178
|
+
base_url="https://api.miosa.ai/api/v1", # default
|
|
179
|
+
timeout=30.0, # seconds, default 30
|
|
180
|
+
max_retries=3, # 429/5xx retries, default 3
|
|
181
|
+
)
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
## Available templates
|
|
185
|
+
|
|
186
|
+
| Template | Description |
|
|
187
|
+
| -------- | ----------- |
|
|
188
|
+
| `miosa-sandbox` | Stable production alias for the current sandbox image. |
|
|
189
|
+
| `debian-12-sandbox-v8` | Debian Bookworm/glibc image with Python, Node, Elixir/Erlang, Go, Rust, Ruby, Java, Postgres, Redis, SQLite, Chromium, and Playwright support. |
|
|
190
|
+
|
|
191
|
+
## Docs
|
|
192
|
+
|
|
193
|
+
Full reference: <https://docs.miosa.ai/sdk/python>.
|
|
194
|
+
|
|
195
|
+
## License
|
|
196
|
+
|
|
197
|
+
MIT
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "miosa-sandbox"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "DEPRECATED — use `miosa` instead"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
requires-python = ">=3.10"
|
|
12
|
+
authors = [
|
|
13
|
+
{ name = "MIOSA", email = "dev@miosa.ai" },
|
|
14
|
+
]
|
|
15
|
+
keywords = ["miosa", "sandbox", "ai", "agents", "code-execution", "sdk"]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Development Status :: 7 - Inactive",
|
|
18
|
+
"Intended Audience :: Developers",
|
|
19
|
+
"License :: OSI Approved :: MIT License",
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"Programming Language :: Python :: 3.10",
|
|
22
|
+
"Programming Language :: Python :: 3.11",
|
|
23
|
+
"Programming Language :: Python :: 3.12",
|
|
24
|
+
"Programming Language :: Python :: 3.13",
|
|
25
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
26
|
+
"Typing :: Typed",
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
dependencies = [
|
|
30
|
+
"httpx>=0.27",
|
|
31
|
+
]
|
|
32
|
+
|
|
33
|
+
[project.optional-dependencies]
|
|
34
|
+
dev = [
|
|
35
|
+
"pytest>=8",
|
|
36
|
+
"pytest-asyncio>=0.23",
|
|
37
|
+
"pytest-httpx>=0.30",
|
|
38
|
+
"ruff>=0.5",
|
|
39
|
+
"mypy>=1.10",
|
|
40
|
+
]
|
|
41
|
+
|
|
42
|
+
[project.urls]
|
|
43
|
+
Homepage = "https://miosa.ai"
|
|
44
|
+
Documentation = "https://docs.miosa.ai/sdk/python"
|
|
45
|
+
Repository = "https://github.com/miosa-ai/miosa"
|
|
46
|
+
Issues = "https://github.com/miosa-ai/miosa/issues"
|
|
47
|
+
|
|
48
|
+
[tool.hatch.build.targets.wheel]
|
|
49
|
+
packages = ["src/miosa_sandbox"]
|
|
50
|
+
|
|
51
|
+
[tool.hatch.build.targets.sdist]
|
|
52
|
+
include = [
|
|
53
|
+
"src/miosa_sandbox",
|
|
54
|
+
"README.md",
|
|
55
|
+
"LICENSE",
|
|
56
|
+
"pyproject.toml",
|
|
57
|
+
]
|
|
58
|
+
|
|
59
|
+
[tool.pytest.ini_options]
|
|
60
|
+
minversion = "8.0"
|
|
61
|
+
testpaths = ["tests"]
|
|
62
|
+
asyncio_mode = "auto"
|
|
63
|
+
filterwarnings = [
|
|
64
|
+
"error",
|
|
65
|
+
"ignore::DeprecationWarning",
|
|
66
|
+
]
|
|
67
|
+
|
|
68
|
+
[tool.ruff]
|
|
69
|
+
line-length = 100
|
|
70
|
+
target-version = "py310"
|
|
71
|
+
src = ["src", "tests"]
|
|
72
|
+
|
|
73
|
+
[tool.ruff.lint]
|
|
74
|
+
select = [
|
|
75
|
+
"E", # pycodestyle errors
|
|
76
|
+
"W", # pycodestyle warnings
|
|
77
|
+
"F", # pyflakes
|
|
78
|
+
"I", # isort
|
|
79
|
+
"B", # flake8-bugbear
|
|
80
|
+
"UP", # pyupgrade
|
|
81
|
+
"SIM", # flake8-simplify
|
|
82
|
+
"RUF", # ruff-specific
|
|
83
|
+
]
|
|
84
|
+
ignore = [
|
|
85
|
+
"E501", # line-too-long handled by formatter
|
|
86
|
+
"B008", # function-call-in-default-argument
|
|
87
|
+
"RUF001", # ambiguous unicode (em-dashes are intentional in docstrings)
|
|
88
|
+
"RUF002", # ambiguous unicode in docstrings
|
|
89
|
+
"RUF003", # ambiguous unicode in comments
|
|
90
|
+
"RUF022", # __all__ ordering (we group by category, not isort)
|
|
91
|
+
]
|
|
92
|
+
|
|
93
|
+
[tool.ruff.lint.per-file-ignores]
|
|
94
|
+
"tests/*" = ["B011", "SIM117"]
|
|
95
|
+
|
|
96
|
+
[tool.mypy]
|
|
97
|
+
python_version = "3.10"
|
|
98
|
+
strict = true
|
|
99
|
+
warn_unused_ignores = true
|
|
100
|
+
warn_redundant_casts = true
|
|
101
|
+
warn_return_any = true
|
|
102
|
+
disallow_untyped_defs = true
|
|
103
|
+
disallow_incomplete_defs = true
|
|
104
|
+
no_implicit_optional = true
|
|
105
|
+
check_untyped_defs = true
|
|
106
|
+
ignore_missing_imports = false
|
|
107
|
+
|
|
108
|
+
[[tool.mypy.overrides]]
|
|
109
|
+
module = "tests.*"
|
|
110
|
+
disallow_untyped_defs = false
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"""miosa-sandbox — Python SDK for the MIOSA platform API.
|
|
2
|
+
|
|
3
|
+
Quickstart (sandboxes)::
|
|
4
|
+
|
|
5
|
+
from miosa_sandbox import MIOSA
|
|
6
|
+
|
|
7
|
+
client = MIOSA(api_key="msk_...")
|
|
8
|
+
with client.sandboxes.create(template_id="python-3.12") as sb:
|
|
9
|
+
result = sb.exec("python3 -c 'print(1+1)'")
|
|
10
|
+
print(result.stdout) # "2\\n"
|
|
11
|
+
|
|
12
|
+
Quickstart (computers with desktop automation)::
|
|
13
|
+
|
|
14
|
+
from miosa_sandbox import MIOSA
|
|
15
|
+
|
|
16
|
+
client = MIOSA(api_key="msk_...")
|
|
17
|
+
pc = client.computers.create("browser-bot", template_type="miosa-desktop")
|
|
18
|
+
pc.wait_until_running()
|
|
19
|
+
screenshot = pc.screenshot()
|
|
20
|
+
pc.click(x=500, y=300)
|
|
21
|
+
pc.type("https://example.com")
|
|
22
|
+
pc.key("Enter")
|
|
23
|
+
pc.destroy()
|
|
24
|
+
|
|
25
|
+
For async::
|
|
26
|
+
|
|
27
|
+
import asyncio
|
|
28
|
+
from miosa_sandbox import AsyncMIOSA
|
|
29
|
+
|
|
30
|
+
async def main():
|
|
31
|
+
async with AsyncMIOSA(api_key="msk_...") as client:
|
|
32
|
+
sb = await client.sandboxes.create(template_id="python-3.12")
|
|
33
|
+
try:
|
|
34
|
+
result = await sb.exec("echo hello")
|
|
35
|
+
print(result.stdout)
|
|
36
|
+
finally:
|
|
37
|
+
await sb.destroy()
|
|
38
|
+
|
|
39
|
+
asyncio.run(main())
|
|
40
|
+
"""
|
|
41
|
+
|
|
42
|
+
from __future__ import annotations
|
|
43
|
+
|
|
44
|
+
from .client import (
|
|
45
|
+
MIOSA,
|
|
46
|
+
AsyncComputerClient,
|
|
47
|
+
AsyncMIOSA,
|
|
48
|
+
AsyncSandboxClient,
|
|
49
|
+
ComputerClient,
|
|
50
|
+
SandboxClient,
|
|
51
|
+
)
|
|
52
|
+
from .computer import AsyncComputer, Computer, ComputerState
|
|
53
|
+
from .errors import (
|
|
54
|
+
ComputerDestroyedError,
|
|
55
|
+
MiosaAPIError,
|
|
56
|
+
MiosaAuthError,
|
|
57
|
+
MiosaError,
|
|
58
|
+
MiosaNetworkError,
|
|
59
|
+
MiosaNotFoundError,
|
|
60
|
+
MiosaRateLimitError,
|
|
61
|
+
MiosaTimeoutError,
|
|
62
|
+
MiosaValidationError,
|
|
63
|
+
SandboxDestroyedError,
|
|
64
|
+
)
|
|
65
|
+
from .sandbox import AsyncSandbox, Sandbox
|
|
66
|
+
from .types import (
|
|
67
|
+
ClientConfig,
|
|
68
|
+
CreateSandboxOptions,
|
|
69
|
+
ExecChunk,
|
|
70
|
+
ExecOptions,
|
|
71
|
+
ExecResult,
|
|
72
|
+
SandboxArtifacts,
|
|
73
|
+
SandboxData,
|
|
74
|
+
SandboxEvent,
|
|
75
|
+
SandboxReadinessProbe,
|
|
76
|
+
SandboxState,
|
|
77
|
+
SandboxTemplate,
|
|
78
|
+
SandboxTemplateList,
|
|
79
|
+
StartTemplateOptions,
|
|
80
|
+
TemplateLifecycleManifest,
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
__version__ = "0.2.0"
|
|
84
|
+
|
|
85
|
+
__all__ = [
|
|
86
|
+
# Top-level clients
|
|
87
|
+
"MIOSA",
|
|
88
|
+
"AsyncMIOSA",
|
|
89
|
+
# Sandbox handles
|
|
90
|
+
"Sandbox",
|
|
91
|
+
"AsyncSandbox",
|
|
92
|
+
# Computer handles
|
|
93
|
+
"Computer",
|
|
94
|
+
"AsyncComputer",
|
|
95
|
+
"ComputerState",
|
|
96
|
+
# Namespace clients (advanced — usually accessed via .sandboxes / .computers)
|
|
97
|
+
"SandboxClient",
|
|
98
|
+
"AsyncSandboxClient",
|
|
99
|
+
"ComputerClient",
|
|
100
|
+
"AsyncComputerClient",
|
|
101
|
+
# Public types
|
|
102
|
+
"ClientConfig",
|
|
103
|
+
"CreateSandboxOptions",
|
|
104
|
+
"ExecChunk",
|
|
105
|
+
"ExecOptions",
|
|
106
|
+
"ExecResult",
|
|
107
|
+
"SandboxArtifacts",
|
|
108
|
+
"SandboxData",
|
|
109
|
+
"SandboxEvent",
|
|
110
|
+
"SandboxReadinessProbe",
|
|
111
|
+
"SandboxState",
|
|
112
|
+
"SandboxTemplate",
|
|
113
|
+
"SandboxTemplateList",
|
|
114
|
+
"StartTemplateOptions",
|
|
115
|
+
"TemplateLifecycleManifest",
|
|
116
|
+
# Errors
|
|
117
|
+
"MiosaError",
|
|
118
|
+
"MiosaAPIError",
|
|
119
|
+
"MiosaAuthError",
|
|
120
|
+
"MiosaNotFoundError",
|
|
121
|
+
"MiosaValidationError",
|
|
122
|
+
"MiosaRateLimitError",
|
|
123
|
+
"MiosaTimeoutError",
|
|
124
|
+
"MiosaNetworkError",
|
|
125
|
+
"SandboxDestroyedError",
|
|
126
|
+
"ComputerDestroyedError",
|
|
127
|
+
# Version
|
|
128
|
+
"__version__",
|
|
129
|
+
]
|