sistemo 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.
- sistemo-0.1.0/LICENSE +202 -0
- sistemo-0.1.0/PKG-INFO +91 -0
- sistemo-0.1.0/README.md +70 -0
- sistemo-0.1.0/pyproject.toml +45 -0
- sistemo-0.1.0/setup.cfg +4 -0
- sistemo-0.1.0/sistemo/__init__.py +35 -0
- sistemo-0.1.0/sistemo/_client.py +205 -0
- sistemo-0.1.0/sistemo/_version.py +16 -0
- sistemo-0.1.0/sistemo/errors.py +67 -0
- sistemo-0.1.0/sistemo/py.typed +0 -0
- sistemo-0.1.0/sistemo/sandbox.py +112 -0
- sistemo-0.1.0/sistemo.egg-info/PKG-INFO +91 -0
- sistemo-0.1.0/sistemo.egg-info/SOURCES.txt +14 -0
- sistemo-0.1.0/sistemo.egg-info/dependency_links.txt +1 -0
- sistemo-0.1.0/sistemo.egg-info/top_level.txt +1 -0
- sistemo-0.1.0/tests/test_sdk.py +462 -0
sistemo-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
sistemo-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: sistemo
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Run AI agents and untrusted code in real isolated microVMs.
|
|
5
|
+
Author: Sistemo
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://sistemo.io
|
|
8
|
+
Project-URL: Documentation, https://docs.sistemo.io
|
|
9
|
+
Project-URL: Repository, https://github.com/sistemo0/sistemo-sdk
|
|
10
|
+
Project-URL: Issues, https://github.com/sistemo0/sistemo-sdk/issues
|
|
11
|
+
Keywords: sandbox,firecracker,microvm,ai-agents,code-execution
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Topic :: Software Development :: Testing
|
|
16
|
+
Classifier: Topic :: System :: Emulators
|
|
17
|
+
Requires-Python: >=3.8
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
License-File: LICENSE
|
|
20
|
+
Dynamic: license-file
|
|
21
|
+
|
|
22
|
+
# sistemo (Python)
|
|
23
|
+
|
|
24
|
+
Run AI agents and untrusted code in **real isolated Firecracker microVMs** — self-host for free or use the cloud.
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
pip install sistemo
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Quickstart (< 10 lines)
|
|
31
|
+
|
|
32
|
+
```python
|
|
33
|
+
from sistemo import Sandbox
|
|
34
|
+
|
|
35
|
+
with Sandbox() as sb: # reads SISTEMO_API_KEY
|
|
36
|
+
result = sb.run("python -c 'print(2 + 2)'")
|
|
37
|
+
print(result.stdout, result.exit_code) # "4\n" 0
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Get an API key from the dashboard (**Dashboard → API Keys**), then:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
export SISTEMO_API_KEY=sk_live_xxxxxxxx
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Configuration
|
|
47
|
+
|
|
48
|
+
| | |
|
|
49
|
+
|---|---|
|
|
50
|
+
| `SISTEMO_API_KEY` | your key (`sk_live_…`). Required. |
|
|
51
|
+
| `SISTEMO_BASE_URL` | override the API URL (default `https://api.sistemo.io`; e.g. your self-hosted control plane). |
|
|
52
|
+
|
|
53
|
+
Or pass them explicitly: `Sandbox(api_key="sk_live_…", base_url="https://…")`.
|
|
54
|
+
|
|
55
|
+
## API
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
sb = Sandbox(vcpus=1, memory_mb=1024, stack="base") # provisions a microVM
|
|
59
|
+
res = sb.run("echo hi && uname -a", timeout=30) # -> ExecResult
|
|
60
|
+
res.stdout, res.stderr, res.exit_code, res.ok
|
|
61
|
+
sb.close() # destroy (or use `with`)
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
A **read** API key can list resources but cannot create sandboxes or run code — use a **full** key with the SDK.
|
|
65
|
+
|
|
66
|
+
## Errors
|
|
67
|
+
|
|
68
|
+
```python
|
|
69
|
+
from sistemo import APIError, AuthError, QuotaExceededError
|
|
70
|
+
|
|
71
|
+
try:
|
|
72
|
+
with Sandbox() as sb:
|
|
73
|
+
sb.run("...")
|
|
74
|
+
except QuotaExceededError as e:
|
|
75
|
+
# An account limit was reached. `detail` names which one and how much is in
|
|
76
|
+
# use. Retrying SUCCEEDS once you free that resource — stop or destroy a
|
|
77
|
+
# machine, delete a volume — or once the limit is raised.
|
|
78
|
+
print(e.detail)
|
|
79
|
+
except AuthError:
|
|
80
|
+
... # 401/403 — key missing/invalid/revoked, or read-only key
|
|
81
|
+
except APIError as e:
|
|
82
|
+
print(e.status, e.detail, e.code)
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Both `QuotaExceededError` and `AuthError` arrive as HTTP 403, so **catch
|
|
86
|
+
`QuotaExceededError` first** — it is a subclass of `APIError`, not of `AuthError`,
|
|
87
|
+
precisely because the two need opposite handling: an auth failure never succeeds
|
|
88
|
+
on retry, a quota refusal does once you free something. `GET /v1/quotas` reports
|
|
89
|
+
every limit alongside current usage.
|
|
90
|
+
|
|
91
|
+
Zero runtime dependencies (Python stdlib only). Apache-2.0.
|
sistemo-0.1.0/README.md
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# sistemo (Python)
|
|
2
|
+
|
|
3
|
+
Run AI agents and untrusted code in **real isolated Firecracker microVMs** — self-host for free or use the cloud.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
pip install sistemo
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
## Quickstart (< 10 lines)
|
|
10
|
+
|
|
11
|
+
```python
|
|
12
|
+
from sistemo import Sandbox
|
|
13
|
+
|
|
14
|
+
with Sandbox() as sb: # reads SISTEMO_API_KEY
|
|
15
|
+
result = sb.run("python -c 'print(2 + 2)'")
|
|
16
|
+
print(result.stdout, result.exit_code) # "4\n" 0
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Get an API key from the dashboard (**Dashboard → API Keys**), then:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
export SISTEMO_API_KEY=sk_live_xxxxxxxx
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Configuration
|
|
26
|
+
|
|
27
|
+
| | |
|
|
28
|
+
|---|---|
|
|
29
|
+
| `SISTEMO_API_KEY` | your key (`sk_live_…`). Required. |
|
|
30
|
+
| `SISTEMO_BASE_URL` | override the API URL (default `https://api.sistemo.io`; e.g. your self-hosted control plane). |
|
|
31
|
+
|
|
32
|
+
Or pass them explicitly: `Sandbox(api_key="sk_live_…", base_url="https://…")`.
|
|
33
|
+
|
|
34
|
+
## API
|
|
35
|
+
|
|
36
|
+
```python
|
|
37
|
+
sb = Sandbox(vcpus=1, memory_mb=1024, stack="base") # provisions a microVM
|
|
38
|
+
res = sb.run("echo hi && uname -a", timeout=30) # -> ExecResult
|
|
39
|
+
res.stdout, res.stderr, res.exit_code, res.ok
|
|
40
|
+
sb.close() # destroy (or use `with`)
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
A **read** API key can list resources but cannot create sandboxes or run code — use a **full** key with the SDK.
|
|
44
|
+
|
|
45
|
+
## Errors
|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
from sistemo import APIError, AuthError, QuotaExceededError
|
|
49
|
+
|
|
50
|
+
try:
|
|
51
|
+
with Sandbox() as sb:
|
|
52
|
+
sb.run("...")
|
|
53
|
+
except QuotaExceededError as e:
|
|
54
|
+
# An account limit was reached. `detail` names which one and how much is in
|
|
55
|
+
# use. Retrying SUCCEEDS once you free that resource — stop or destroy a
|
|
56
|
+
# machine, delete a volume — or once the limit is raised.
|
|
57
|
+
print(e.detail)
|
|
58
|
+
except AuthError:
|
|
59
|
+
... # 401/403 — key missing/invalid/revoked, or read-only key
|
|
60
|
+
except APIError as e:
|
|
61
|
+
print(e.status, e.detail, e.code)
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Both `QuotaExceededError` and `AuthError` arrive as HTTP 403, so **catch
|
|
65
|
+
`QuotaExceededError` first** — it is a subclass of `APIError`, not of `AuthError`,
|
|
66
|
+
precisely because the two need opposite handling: an auth failure never succeeds
|
|
67
|
+
on retry, a quota refusal does once you free something. `GET /v1/quotas` reports
|
|
68
|
+
every limit alongside current usage.
|
|
69
|
+
|
|
70
|
+
Zero runtime dependencies (Python stdlib only). Apache-2.0.
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
# >=77 for PEP 639: `license` as an SPDX string + license-files.
|
|
3
|
+
requires = ["setuptools>=77"]
|
|
4
|
+
build-backend = "setuptools.build_meta"
|
|
5
|
+
|
|
6
|
+
[project]
|
|
7
|
+
name = "sistemo"
|
|
8
|
+
version = "0.1.0"
|
|
9
|
+
description = "Run AI agents and untrusted code in real isolated microVMs."
|
|
10
|
+
readme = "README.md"
|
|
11
|
+
requires-python = ">=3.8"
|
|
12
|
+
license = "Apache-2.0"
|
|
13
|
+
license-files = ["LICENSE"]
|
|
14
|
+
authors = [{ name = "Sistemo" }]
|
|
15
|
+
keywords = ["sandbox", "firecracker", "microvm", "ai-agents", "code-execution"]
|
|
16
|
+
dependencies = [] # zero runtime dependencies — stdlib only
|
|
17
|
+
|
|
18
|
+
classifiers = [
|
|
19
|
+
"Development Status :: 4 - Beta",
|
|
20
|
+
"Intended Audience :: Developers",
|
|
21
|
+
"Programming Language :: Python :: 3",
|
|
22
|
+
"Topic :: Software Development :: Testing",
|
|
23
|
+
"Topic :: System :: Emulators",
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
[project.urls]
|
|
27
|
+
Homepage = "https://sistemo.io"
|
|
28
|
+
Documentation = "https://docs.sistemo.io"
|
|
29
|
+
# ⚠ These render as clickable links on the PyPI project page. They previously
|
|
30
|
+
# pointed at a PRIVATE GitLab path, which resolves to a sign-in wall (HTTP 403)
|
|
31
|
+
# — the worst possible landing for an open-core "audit it yourself" pitch.
|
|
32
|
+
# Whatever repo is published must be PUBLIC and must actually exist.
|
|
33
|
+
Repository = "https://github.com/sistemo0/sistemo-sdk"
|
|
34
|
+
Issues = "https://github.com/sistemo0/sistemo-sdk/issues"
|
|
35
|
+
|
|
36
|
+
[tool.setuptools.packages.find]
|
|
37
|
+
where = ["."]
|
|
38
|
+
include = ["sistemo*"]
|
|
39
|
+
|
|
40
|
+
# PEP 561. Without this marker the package ships fully annotated and every type
|
|
41
|
+
# checker ignores it — `mypy`/`pyright` treat an installed `sistemo` as Any, so
|
|
42
|
+
# the types this SDK is written with never reach the developer who installed it.
|
|
43
|
+
# The marker is only honoured if it is actually IN the wheel, hence package-data.
|
|
44
|
+
[tool.setuptools.package-data]
|
|
45
|
+
sistemo = ["py.typed"]
|
sistemo-0.1.0/setup.cfg
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"""Sistemo — run AI agents and untrusted code in real isolated microVMs.
|
|
2
|
+
|
|
3
|
+
Quickstart::
|
|
4
|
+
|
|
5
|
+
from sistemo import Sandbox
|
|
6
|
+
|
|
7
|
+
with Sandbox() as sb: # reads SISTEMO_API_KEY
|
|
8
|
+
result = sb.run("python -c 'print(2 + 2)'")
|
|
9
|
+
print(result.stdout, result.exit_code)
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from ._client import Client
|
|
13
|
+
from ._version import __version__
|
|
14
|
+
from .errors import (
|
|
15
|
+
APIError,
|
|
16
|
+
AuthError,
|
|
17
|
+
NotFoundError,
|
|
18
|
+
QuotaExceededError,
|
|
19
|
+
RateLimitError,
|
|
20
|
+
SistemoError,
|
|
21
|
+
)
|
|
22
|
+
from .sandbox import ExecResult, Sandbox
|
|
23
|
+
|
|
24
|
+
__all__ = [
|
|
25
|
+
"Sandbox",
|
|
26
|
+
"ExecResult",
|
|
27
|
+
"Client",
|
|
28
|
+
"SistemoError",
|
|
29
|
+
"APIError",
|
|
30
|
+
"AuthError",
|
|
31
|
+
"QuotaExceededError",
|
|
32
|
+
"NotFoundError",
|
|
33
|
+
"RateLimitError",
|
|
34
|
+
"__version__",
|
|
35
|
+
]
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
"""Thin HTTP client for the Sistemo control-plane API (stdlib only, no deps)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
import os
|
|
7
|
+
import random
|
|
8
|
+
import socket
|
|
9
|
+
import time
|
|
10
|
+
import urllib.error
|
|
11
|
+
import urllib.request
|
|
12
|
+
import uuid
|
|
13
|
+
from typing import Any, Mapping
|
|
14
|
+
|
|
15
|
+
from ._version import __version__
|
|
16
|
+
from .errors import APIError, SistemoError, api_error
|
|
17
|
+
|
|
18
|
+
DEFAULT_BASE_URL = "https://api.sistemo.io"
|
|
19
|
+
|
|
20
|
+
# Sent on every request. A real User-Agent is required: the default urllib UA
|
|
21
|
+
# (``Python-urllib/x.y``) is blocked by the production WAF (Cloudflare → 403).
|
|
22
|
+
USER_AGENT = f"sistemo-python/{__version__}"
|
|
23
|
+
|
|
24
|
+
# Transient HTTP statuses worth retrying (with care — see request()).
|
|
25
|
+
_RETRY_STATUSES = frozenset({408, 429, 500, 502, 503, 504})
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class Client:
|
|
29
|
+
"""Low-level API client. Most users want :class:`sistemo.Sandbox` instead.
|
|
30
|
+
|
|
31
|
+
The API key is read from ``api_key=`` or the ``SISTEMO_API_KEY`` env var.
|
|
32
|
+
The base URL is ``base_url=`` or ``SISTEMO_BASE_URL`` (default production).
|
|
33
|
+
|
|
34
|
+
Retries (default max 3 attempts): connection failures always; HTTP
|
|
35
|
+
408/429/5xx only when safe (GET/DELETE, or POST/PUT/PATCH with an
|
|
36
|
+
``Idempotency-Key``). Exec without an idempotency key is **not** retried
|
|
37
|
+
on HTTP errors (would re-run the guest script).
|
|
38
|
+
"""
|
|
39
|
+
|
|
40
|
+
def __init__(
|
|
41
|
+
self,
|
|
42
|
+
api_key: str | None = None,
|
|
43
|
+
base_url: str | None = None,
|
|
44
|
+
timeout: float = 120.0,
|
|
45
|
+
*,
|
|
46
|
+
max_retries: int = 2,
|
|
47
|
+
retry_backoff: float = 0.4,
|
|
48
|
+
retry_max_backoff: float = 8.0,
|
|
49
|
+
):
|
|
50
|
+
self.api_key = api_key or os.environ.get("SISTEMO_API_KEY")
|
|
51
|
+
if not self.api_key:
|
|
52
|
+
raise SistemoError(
|
|
53
|
+
"no API key — pass api_key= or set the SISTEMO_API_KEY environment variable"
|
|
54
|
+
)
|
|
55
|
+
self.base_url = (
|
|
56
|
+
base_url or os.environ.get("SISTEMO_BASE_URL") or DEFAULT_BASE_URL
|
|
57
|
+
).rstrip("/")
|
|
58
|
+
self.timeout = timeout
|
|
59
|
+
self.max_retries = max(0, max_retries)
|
|
60
|
+
self.retry_backoff = retry_backoff
|
|
61
|
+
self.retry_max_backoff = retry_max_backoff
|
|
62
|
+
|
|
63
|
+
def request(
|
|
64
|
+
self,
|
|
65
|
+
method: str,
|
|
66
|
+
path: str,
|
|
67
|
+
body: dict | None = None,
|
|
68
|
+
*,
|
|
69
|
+
headers: Mapping[str, str] | None = None,
|
|
70
|
+
idempotency_key: str | None = None,
|
|
71
|
+
max_retries: int | None = None,
|
|
72
|
+
) -> Any:
|
|
73
|
+
"""HTTP JSON request with optional retries.
|
|
74
|
+
|
|
75
|
+
Pass ``idempotency_key`` for create (and other POSTs you may safely
|
|
76
|
+
retry). Pass ``max_retries=0`` to disable retries for one call (e.g. exec).
|
|
77
|
+
"""
|
|
78
|
+
retries = self.max_retries if max_retries is None else max(0, max_retries)
|
|
79
|
+
method_u = method.upper()
|
|
80
|
+
last_err: BaseException | None = None
|
|
81
|
+
|
|
82
|
+
for attempt in range(retries + 1):
|
|
83
|
+
try:
|
|
84
|
+
return self._once(
|
|
85
|
+
method_u, path, body, headers=headers, idempotency_key=idempotency_key
|
|
86
|
+
)
|
|
87
|
+
except APIError as e:
|
|
88
|
+
last_err = e
|
|
89
|
+
if attempt >= retries or not self._should_retry_http(
|
|
90
|
+
method_u, e.status, idempotency_key
|
|
91
|
+
):
|
|
92
|
+
raise
|
|
93
|
+
self._sleep(attempt, e)
|
|
94
|
+
except SistemoError as e:
|
|
95
|
+
# connection / timeout
|
|
96
|
+
last_err = e
|
|
97
|
+
if attempt >= retries:
|
|
98
|
+
raise
|
|
99
|
+
self._sleep(attempt, None)
|
|
100
|
+
|
|
101
|
+
assert last_err is not None
|
|
102
|
+
raise last_err
|
|
103
|
+
|
|
104
|
+
def _once(
|
|
105
|
+
self,
|
|
106
|
+
method: str,
|
|
107
|
+
path: str,
|
|
108
|
+
body: dict | None,
|
|
109
|
+
*,
|
|
110
|
+
headers: Mapping[str, str] | None,
|
|
111
|
+
idempotency_key: str | None,
|
|
112
|
+
) -> Any:
|
|
113
|
+
data = json.dumps(body).encode("utf-8") if body is not None else None
|
|
114
|
+
req = urllib.request.Request(self.base_url + path, data=data, method=method)
|
|
115
|
+
req.add_header("Authorization", f"Bearer {self.api_key}")
|
|
116
|
+
req.add_header("Accept", "application/json")
|
|
117
|
+
req.add_header("User-Agent", USER_AGENT)
|
|
118
|
+
if data is not None:
|
|
119
|
+
req.add_header("Content-Type", "application/json")
|
|
120
|
+
if idempotency_key:
|
|
121
|
+
req.add_header("Idempotency-Key", idempotency_key)
|
|
122
|
+
if headers:
|
|
123
|
+
for k, v in headers.items():
|
|
124
|
+
req.add_header(k, v)
|
|
125
|
+
try:
|
|
126
|
+
with urllib.request.urlopen(req, timeout=self.timeout) as resp:
|
|
127
|
+
raw = resp.read()
|
|
128
|
+
return json.loads(raw) if raw else {}
|
|
129
|
+
except urllib.error.HTTPError as e:
|
|
130
|
+
raw = e.read()
|
|
131
|
+
detail, code = "request failed", None
|
|
132
|
+
try:
|
|
133
|
+
parsed = json.loads(raw)
|
|
134
|
+
detail = parsed.get("detail", detail)
|
|
135
|
+
code = parsed.get("code")
|
|
136
|
+
except Exception:
|
|
137
|
+
pass
|
|
138
|
+
raise api_error(e.code, detail, code) from None
|
|
139
|
+
except urllib.error.URLError as e:
|
|
140
|
+
raise SistemoError(f"connection error: {e.reason}") from e
|
|
141
|
+
except (socket.timeout, TimeoutError) as e:
|
|
142
|
+
# ⚠ socket.timeout is only an alias of TimeoutError from Python 3.10.
|
|
143
|
+
# On the 3.8/3.9 floor this package declares, a READ timeout raises
|
|
144
|
+
# socket.timeout directly — urlopen does not wrap it in URLError —
|
|
145
|
+
# so catching TimeoutError alone let a raw stdlib exception escape
|
|
146
|
+
# to the caller and skipped the connection-retry path entirely.
|
|
147
|
+
raise SistemoError(f"connection error: timeout ({e})") from e
|
|
148
|
+
|
|
149
|
+
def _should_retry_http(
|
|
150
|
+
self, method: str, status: int, idempotency_key: str | None
|
|
151
|
+
) -> bool:
|
|
152
|
+
if status not in _RETRY_STATUSES:
|
|
153
|
+
return False
|
|
154
|
+
# Safe methods + DELETE (destroy is idempotent enough for retry).
|
|
155
|
+
if method in ("GET", "HEAD", "OPTIONS", "DELETE"):
|
|
156
|
+
return True
|
|
157
|
+
# Mutating methods only when the caller opted into idempotency.
|
|
158
|
+
return bool(idempotency_key)
|
|
159
|
+
|
|
160
|
+
def _sleep(self, attempt: int, err: APIError | None) -> None:
|
|
161
|
+
# Exponential backoff + jitter. Honour Retry-After seconds if present later.
|
|
162
|
+
base = min(self.retry_max_backoff, self.retry_backoff * (2**attempt))
|
|
163
|
+
delay = base * (0.5 + random.random()) # full jitter around [0.5x, 1.5x]
|
|
164
|
+
if err is not None and err.status == 429:
|
|
165
|
+
delay = max(delay, min(self.retry_max_backoff, base))
|
|
166
|
+
time.sleep(delay)
|
|
167
|
+
|
|
168
|
+
# --- volumes (incl. detachable root volumes) ---------------------------
|
|
169
|
+
|
|
170
|
+
def list_volumes(self) -> list[dict]:
|
|
171
|
+
"""List the account's volumes (root and data)."""
|
|
172
|
+
# API may return "volumes": null when empty — never hand back None.
|
|
173
|
+
return self.request("GET", "/v1/volumes").get("volumes") or []
|
|
174
|
+
|
|
175
|
+
def create_volume(self, name: str, size_gb: int) -> dict:
|
|
176
|
+
"""Create a standalone data volume."""
|
|
177
|
+
return self.request(
|
|
178
|
+
"POST",
|
|
179
|
+
"/v1/volumes",
|
|
180
|
+
{"name": name, "size_gb": size_gb},
|
|
181
|
+
idempotency_key=str(uuid.uuid4()),
|
|
182
|
+
)
|
|
183
|
+
|
|
184
|
+
def attach_volume(self, machine_id: str, volume_id: str) -> dict:
|
|
185
|
+
"""Attach a volume (root or data) to a STOPPED machine."""
|
|
186
|
+
return self.request(
|
|
187
|
+
"POST",
|
|
188
|
+
f"/v1/machines/{machine_id}/volume/attach",
|
|
189
|
+
{"volume_id": volume_id},
|
|
190
|
+
idempotency_key=str(uuid.uuid4()),
|
|
191
|
+
)
|
|
192
|
+
|
|
193
|
+
def detach_volume(self, machine_id: str, volume_id: str) -> dict:
|
|
194
|
+
"""Detach a volume from a STOPPED machine. A detached root volume's disk
|
|
195
|
+
is preserved and can be re-attached or booted onto a new sandbox."""
|
|
196
|
+
return self.request(
|
|
197
|
+
"POST",
|
|
198
|
+
f"/v1/machines/{machine_id}/volume/detach",
|
|
199
|
+
{"volume_id": volume_id},
|
|
200
|
+
idempotency_key=str(uuid.uuid4()),
|
|
201
|
+
)
|
|
202
|
+
|
|
203
|
+
def delete_volume(self, volume_id: str) -> dict:
|
|
204
|
+
"""Delete a detached volume."""
|
|
205
|
+
return self.request("DELETE", f"/v1/volumes/{volume_id}")
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"""The single definition of this package's version.
|
|
2
|
+
|
|
3
|
+
⚠ ONE definition on purpose. The version appears in three places that MUST
|
|
4
|
+
agree: this constant, ``pyproject.toml``, and the ``User-Agent`` header — and
|
|
5
|
+
the UA is not cosmetic, because the production WAF blocks generic library UAs,
|
|
6
|
+
so it is the string that has to be right for the SDK to work at all.
|
|
7
|
+
|
|
8
|
+
Before this module the three were independent literals and only two of them
|
|
9
|
+
were checked by CI (the release job compares the git tag to ``pyproject.toml``).
|
|
10
|
+
A release could therefore ship a package versioned 0.2.0 that introduced itself
|
|
11
|
+
to the API as ``sistemo-python/0.1.0`` — the exact "two definitions meant to
|
|
12
|
+
agree" drift this project keeps getting bitten by. ``_client`` now derives the
|
|
13
|
+
UA from here, and ``test_version_matches_pyproject`` pins the third.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
__version__ = "0.1.0"
|