eryx-run 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.
- eryx_run-0.1.0/.gitignore +13 -0
- eryx_run-0.1.0/LICENSE-APACHE +201 -0
- eryx_run-0.1.0/LICENSE-MIT +21 -0
- eryx_run-0.1.0/PKG-INFO +116 -0
- eryx_run-0.1.0/README.md +96 -0
- eryx_run-0.1.0/pyproject.toml +39 -0
- eryx_run-0.1.0/src/eryx_run/__init__.py +65 -0
- eryx_run-0.1.0/src/eryx_run/_callbacks.py +110 -0
- eryx_run-0.1.0/src/eryx_run/_client.py +203 -0
- eryx_run-0.1.0/src/eryx_run/_errors.py +137 -0
- eryx_run-0.1.0/src/eryx_run/_sandbox.py +264 -0
- eryx_run-0.1.0/src/eryx_run/_types.py +121 -0
- eryx_run-0.1.0/src/eryx_run/py.typed +0 -0
- eryx_run-0.1.0/tests/test_fake.py +451 -0
- eryx_run-0.1.0/tests/test_live.py +104 -0
- eryx_run-0.1.0/uv.lock +849 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Allowlist: ignore everything here except the package's own files, so
|
|
2
|
+
# virtualenvs, caches, build output and local env files stay out.
|
|
3
|
+
/*
|
|
4
|
+
!/.gitignore
|
|
5
|
+
!/README.md
|
|
6
|
+
!/pyproject.toml
|
|
7
|
+
!/uv.lock
|
|
8
|
+
!/LICENSE-MIT
|
|
9
|
+
!/LICENSE-APACHE
|
|
10
|
+
!/src/
|
|
11
|
+
!/tests/
|
|
12
|
+
__pycache__/
|
|
13
|
+
*.py[cod]
|
|
@@ -0,0 +1,201 @@
|
|
|
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
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Ben Sully
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ben Sully <ben.sully88@gmail.com>
|
|
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 all
|
|
13
|
+
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 THE
|
|
21
|
+
SOFTWARE.
|
eryx_run-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: eryx-run
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Run Python in an eryx sandbox on eryx.run, with the same API as pyeryx
|
|
5
|
+
Project-URL: Homepage, https://eryx.run
|
|
6
|
+
Project-URL: Documentation, https://eryx.run/docs
|
|
7
|
+
Project-URL: Repository, https://github.com/eryx-org/eryx
|
|
8
|
+
License-Expression: MIT OR Apache-2.0
|
|
9
|
+
License-File: LICENSE-APACHE
|
|
10
|
+
License-File: LICENSE-MIT
|
|
11
|
+
Keywords: eryx,isolation,sandbox,security,wasm,webassembly
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Typing :: Typed
|
|
16
|
+
Requires-Python: >=3.10
|
|
17
|
+
Requires-Dist: httpx>=0.27
|
|
18
|
+
Requires-Dist: websockets>=14
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
|
|
21
|
+
# eryx-run
|
|
22
|
+
|
|
23
|
+
Run untrusted Python in an [eryx](https://github.com/eryx-org/eryx) sandbox on
|
|
24
|
+
[eryx.run](https://eryx.run), with the same API as
|
|
25
|
+
[pyeryx](https://pypi.org/project/pyeryx/), which runs sandboxes in your own
|
|
26
|
+
process. Moving between the two is an import:
|
|
27
|
+
|
|
28
|
+
```python
|
|
29
|
+
import eryx_run as eryx # or: import eryx
|
|
30
|
+
|
|
31
|
+
sandbox = eryx.Sandbox()
|
|
32
|
+
result = sandbox.execute("print(2 + 2)")
|
|
33
|
+
print(result.stdout_text) # 4
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
eryx-run is pure Python (it depends on `httpx` and `websockets`), so it
|
|
37
|
+
installs anywhere, with no WebAssembly runtime of its own.
|
|
38
|
+
|
|
39
|
+
```sh
|
|
40
|
+
pip install eryx-run
|
|
41
|
+
export ERYX_API_KEY=eryx_... # from https://app.eryx.run
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Callbacks
|
|
45
|
+
|
|
46
|
+
Sandboxed code can `await` functions you provide. They run in your process,
|
|
47
|
+
sync or async:
|
|
48
|
+
|
|
49
|
+
```python
|
|
50
|
+
import eryx_run as eryx
|
|
51
|
+
|
|
52
|
+
callbacks = eryx.CallbackRegistry()
|
|
53
|
+
|
|
54
|
+
@callbacks.callback(description="Look up a user by id")
|
|
55
|
+
async def get_user(id: int) -> dict:
|
|
56
|
+
return {"id": id, "name": "Ada"}
|
|
57
|
+
|
|
58
|
+
sandbox = eryx.Sandbox(callbacks=callbacks)
|
|
59
|
+
result = sandbox.execute("""
|
|
60
|
+
user = await get_user(id=123)
|
|
61
|
+
print(user["name"])
|
|
62
|
+
""")
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Code calls them with keyword arguments. pyeryx's list-of-dicts form works too:
|
|
66
|
+
`callbacks=[{"name": "get_user", "fn": get_user}]`.
|
|
67
|
+
|
|
68
|
+
## Results and errors
|
|
69
|
+
|
|
70
|
+
`execute` returns an `ExecuteResult` (`stdout`, `stderr`, `stdout_text`,
|
|
71
|
+
`duration_ms`, `fuel_consumed`, `result`, ...). Set a variable called `result`
|
|
72
|
+
to return a value:
|
|
73
|
+
|
|
74
|
+
```python
|
|
75
|
+
sandbox.execute("result = {'answer': 42}").result # {'answer': 42}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
A run that fails raises what pyeryx raises: `PythonExceptionError` (with
|
|
79
|
+
`stdout` and `stderr`) when the code raises, `TimeoutError`, or
|
|
80
|
+
`ResourceLimitError`. Requests eryx.run refuses raise an `APIError` subclass:
|
|
81
|
+
`AuthenticationError`, `RateLimitError` (with `retry_after`),
|
|
82
|
+
`NotFoundError`, `ConflictError`, `InvalidRequestError` or
|
|
83
|
+
`ServiceUnavailableError`; `APIConnectionError` if eryx.run can't be reached or
|
|
84
|
+
the connection drops mid-run. All of them are `EryxError`s.
|
|
85
|
+
|
|
86
|
+
From asyncio, use `await sandbox.execute_async(code)`.
|
|
87
|
+
|
|
88
|
+
## Sessions
|
|
89
|
+
|
|
90
|
+
A `Session` keeps variables, imports and files under `/data` between runs:
|
|
91
|
+
|
|
92
|
+
```python
|
|
93
|
+
session = eryx.Session()
|
|
94
|
+
session.execute("x = 21")
|
|
95
|
+
session.execute("print(x * 2)").stdout_text # "42\n"
|
|
96
|
+
session.delete()
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
`Session(id=...)` uses an existing session, such as one another process
|
|
100
|
+
created (`session.id`).
|
|
101
|
+
|
|
102
|
+
## What's different from pyeryx
|
|
103
|
+
|
|
104
|
+
- **Limits:** `ResourceLimits(execution_timeout_ms=..., max_fuel=...)`; `None`
|
|
105
|
+
(the default) means your org's limit. eryx.run sets memory and callback
|
|
106
|
+
limits itself.
|
|
107
|
+
- **Hosted-only arguments:** `environment` (an environment you uploaded),
|
|
108
|
+
`connections` (MCP servers), `network_policies`, and `api_key` / `base_url`
|
|
109
|
+
(defaults `$ERYX_API_KEY` and `$ERYX_URL`).
|
|
110
|
+
- **Local-only arguments** raise a `ValueError` saying what to use instead:
|
|
111
|
+
`network`, `secrets` and `scrub_*` (use network policies), `mcp` (use
|
|
112
|
+
connections), `volumes`, `on_stdout` / `on_stderr` and `cancel` (not yet),
|
|
113
|
+
and `result_variable` other than `result`. Sessions don't have
|
|
114
|
+
`snapshot_state` / `restore_state`: eryx.run keeps the state.
|
|
115
|
+
|
|
116
|
+
See the [API reference](https://eryx.run/docs) for the limits and errors.
|
eryx_run-0.1.0/README.md
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# eryx-run
|
|
2
|
+
|
|
3
|
+
Run untrusted Python in an [eryx](https://github.com/eryx-org/eryx) sandbox on
|
|
4
|
+
[eryx.run](https://eryx.run), with the same API as
|
|
5
|
+
[pyeryx](https://pypi.org/project/pyeryx/), which runs sandboxes in your own
|
|
6
|
+
process. Moving between the two is an import:
|
|
7
|
+
|
|
8
|
+
```python
|
|
9
|
+
import eryx_run as eryx # or: import eryx
|
|
10
|
+
|
|
11
|
+
sandbox = eryx.Sandbox()
|
|
12
|
+
result = sandbox.execute("print(2 + 2)")
|
|
13
|
+
print(result.stdout_text) # 4
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
eryx-run is pure Python (it depends on `httpx` and `websockets`), so it
|
|
17
|
+
installs anywhere, with no WebAssembly runtime of its own.
|
|
18
|
+
|
|
19
|
+
```sh
|
|
20
|
+
pip install eryx-run
|
|
21
|
+
export ERYX_API_KEY=eryx_... # from https://app.eryx.run
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Callbacks
|
|
25
|
+
|
|
26
|
+
Sandboxed code can `await` functions you provide. They run in your process,
|
|
27
|
+
sync or async:
|
|
28
|
+
|
|
29
|
+
```python
|
|
30
|
+
import eryx_run as eryx
|
|
31
|
+
|
|
32
|
+
callbacks = eryx.CallbackRegistry()
|
|
33
|
+
|
|
34
|
+
@callbacks.callback(description="Look up a user by id")
|
|
35
|
+
async def get_user(id: int) -> dict:
|
|
36
|
+
return {"id": id, "name": "Ada"}
|
|
37
|
+
|
|
38
|
+
sandbox = eryx.Sandbox(callbacks=callbacks)
|
|
39
|
+
result = sandbox.execute("""
|
|
40
|
+
user = await get_user(id=123)
|
|
41
|
+
print(user["name"])
|
|
42
|
+
""")
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Code calls them with keyword arguments. pyeryx's list-of-dicts form works too:
|
|
46
|
+
`callbacks=[{"name": "get_user", "fn": get_user}]`.
|
|
47
|
+
|
|
48
|
+
## Results and errors
|
|
49
|
+
|
|
50
|
+
`execute` returns an `ExecuteResult` (`stdout`, `stderr`, `stdout_text`,
|
|
51
|
+
`duration_ms`, `fuel_consumed`, `result`, ...). Set a variable called `result`
|
|
52
|
+
to return a value:
|
|
53
|
+
|
|
54
|
+
```python
|
|
55
|
+
sandbox.execute("result = {'answer': 42}").result # {'answer': 42}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
A run that fails raises what pyeryx raises: `PythonExceptionError` (with
|
|
59
|
+
`stdout` and `stderr`) when the code raises, `TimeoutError`, or
|
|
60
|
+
`ResourceLimitError`. Requests eryx.run refuses raise an `APIError` subclass:
|
|
61
|
+
`AuthenticationError`, `RateLimitError` (with `retry_after`),
|
|
62
|
+
`NotFoundError`, `ConflictError`, `InvalidRequestError` or
|
|
63
|
+
`ServiceUnavailableError`; `APIConnectionError` if eryx.run can't be reached or
|
|
64
|
+
the connection drops mid-run. All of them are `EryxError`s.
|
|
65
|
+
|
|
66
|
+
From asyncio, use `await sandbox.execute_async(code)`.
|
|
67
|
+
|
|
68
|
+
## Sessions
|
|
69
|
+
|
|
70
|
+
A `Session` keeps variables, imports and files under `/data` between runs:
|
|
71
|
+
|
|
72
|
+
```python
|
|
73
|
+
session = eryx.Session()
|
|
74
|
+
session.execute("x = 21")
|
|
75
|
+
session.execute("print(x * 2)").stdout_text # "42\n"
|
|
76
|
+
session.delete()
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
`Session(id=...)` uses an existing session, such as one another process
|
|
80
|
+
created (`session.id`).
|
|
81
|
+
|
|
82
|
+
## What's different from pyeryx
|
|
83
|
+
|
|
84
|
+
- **Limits:** `ResourceLimits(execution_timeout_ms=..., max_fuel=...)`; `None`
|
|
85
|
+
(the default) means your org's limit. eryx.run sets memory and callback
|
|
86
|
+
limits itself.
|
|
87
|
+
- **Hosted-only arguments:** `environment` (an environment you uploaded),
|
|
88
|
+
`connections` (MCP servers), `network_policies`, and `api_key` / `base_url`
|
|
89
|
+
(defaults `$ERYX_API_KEY` and `$ERYX_URL`).
|
|
90
|
+
- **Local-only arguments** raise a `ValueError` saying what to use instead:
|
|
91
|
+
`network`, `secrets` and `scrub_*` (use network policies), `mcp` (use
|
|
92
|
+
connections), `volumes`, `on_stdout` / `on_stderr` and `cancel` (not yet),
|
|
93
|
+
and `result_variable` other than `result`. Sessions don't have
|
|
94
|
+
`snapshot_state` / `restore_state`: eryx.run keeps the state.
|
|
95
|
+
|
|
96
|
+
See the [API reference](https://eryx.run/docs) for the limits and errors.
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.27"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "eryx-run"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Run Python in an eryx sandbox on eryx.run, with the same API as pyeryx"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = "MIT OR Apache-2.0"
|
|
12
|
+
license-files = ["LICENSE-MIT", "LICENSE-APACHE"]
|
|
13
|
+
keywords = ["sandbox", "wasm", "webassembly", "security", "isolation", "eryx"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 3 - Alpha",
|
|
16
|
+
"Intended Audience :: Developers",
|
|
17
|
+
"Programming Language :: Python :: 3",
|
|
18
|
+
"Typing :: Typed",
|
|
19
|
+
]
|
|
20
|
+
dependencies = ["httpx>=0.27", "websockets>=14"]
|
|
21
|
+
|
|
22
|
+
[project.urls]
|
|
23
|
+
Homepage = "https://eryx.run"
|
|
24
|
+
Documentation = "https://eryx.run/docs"
|
|
25
|
+
Repository = "https://github.com/eryx-org/eryx"
|
|
26
|
+
|
|
27
|
+
[dependency-groups]
|
|
28
|
+
dev = ["pytest>=8", "pytest-asyncio>=0.24", "mypy>=1.11"]
|
|
29
|
+
|
|
30
|
+
[tool.hatch.build.targets.wheel]
|
|
31
|
+
packages = ["src/eryx_run"]
|
|
32
|
+
|
|
33
|
+
[tool.pytest.ini_options]
|
|
34
|
+
asyncio_mode = "auto"
|
|
35
|
+
asyncio_default_fixture_loop_scope = "function"
|
|
36
|
+
|
|
37
|
+
[tool.mypy]
|
|
38
|
+
strict = true
|
|
39
|
+
files = ["src", "tests"]
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"""eryx.run: run Python in an eryx sandbox, hosted.
|
|
2
|
+
|
|
3
|
+
The same API as pyeryx (``import eryx``) for what both can do, so moving
|
|
4
|
+
between running sandboxes yourself and on eryx.run is an import:
|
|
5
|
+
|
|
6
|
+
>>> import eryx_run as eryx
|
|
7
|
+
>>> sandbox = eryx.Sandbox() # uses $ERYX_API_KEY
|
|
8
|
+
>>> result = sandbox.execute("print(2 + 2)")
|
|
9
|
+
>>> print(result.stdout_text)
|
|
10
|
+
4
|
|
11
|
+
|
|
12
|
+
Callbacks work as in pyeryx: sandboxed code ``await``s them, and they run
|
|
13
|
+
here, in your process.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
from ._callbacks import CallbackDict, CallbackRegistry
|
|
17
|
+
from ._client import DEFAULT_URL, PROTOCOL
|
|
18
|
+
from ._errors import (
|
|
19
|
+
APIConnectionError,
|
|
20
|
+
APIError,
|
|
21
|
+
AuthenticationError,
|
|
22
|
+
CancelledError,
|
|
23
|
+
ConflictError,
|
|
24
|
+
EryxError,
|
|
25
|
+
ExecutionError,
|
|
26
|
+
InitializationError,
|
|
27
|
+
InvalidRequestError,
|
|
28
|
+
NotFoundError,
|
|
29
|
+
PythonExceptionError,
|
|
30
|
+
RateLimitError,
|
|
31
|
+
ResourceLimitError,
|
|
32
|
+
ServiceUnavailableError,
|
|
33
|
+
TimeoutError,
|
|
34
|
+
)
|
|
35
|
+
from ._sandbox import Sandbox, Session
|
|
36
|
+
from ._types import ExecuteResult, ResourceLimits
|
|
37
|
+
|
|
38
|
+
__version__ = "0.1.0"
|
|
39
|
+
|
|
40
|
+
__all__ = [
|
|
41
|
+
"APIConnectionError",
|
|
42
|
+
"APIError",
|
|
43
|
+
"AuthenticationError",
|
|
44
|
+
"CallbackDict",
|
|
45
|
+
"CallbackRegistry",
|
|
46
|
+
"CancelledError",
|
|
47
|
+
"ConflictError",
|
|
48
|
+
"DEFAULT_URL",
|
|
49
|
+
"EryxError",
|
|
50
|
+
"ExecuteResult",
|
|
51
|
+
"ExecutionError",
|
|
52
|
+
"InitializationError",
|
|
53
|
+
"InvalidRequestError",
|
|
54
|
+
"NotFoundError",
|
|
55
|
+
"PROTOCOL",
|
|
56
|
+
"PythonExceptionError",
|
|
57
|
+
"RateLimitError",
|
|
58
|
+
"ResourceLimitError",
|
|
59
|
+
"ResourceLimits",
|
|
60
|
+
"Sandbox",
|
|
61
|
+
"ServiceUnavailableError",
|
|
62
|
+
"Session",
|
|
63
|
+
"TimeoutError",
|
|
64
|
+
"__version__",
|
|
65
|
+
]
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"""Callbacks: host functions sandboxed code can ``await``, as in pyeryx."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import asyncio
|
|
6
|
+
import inspect
|
|
7
|
+
from collections.abc import Iterator, Sequence
|
|
8
|
+
from typing import Any, Callable, Optional, TypedDict, TypeVar, Union
|
|
9
|
+
|
|
10
|
+
F = TypeVar("F", bound=Callable[..., Any])
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class CallbackDict(TypedDict, total=False):
|
|
14
|
+
"""Dictionary format for defining callbacks, as in pyeryx."""
|
|
15
|
+
|
|
16
|
+
name: str
|
|
17
|
+
"""The callback name (required)."""
|
|
18
|
+
|
|
19
|
+
fn: Callable[..., Any]
|
|
20
|
+
"""The callback function, sync or async (required)."""
|
|
21
|
+
|
|
22
|
+
description: str
|
|
23
|
+
"""Optional description of what the callback does."""
|
|
24
|
+
|
|
25
|
+
schema: dict[str, Any]
|
|
26
|
+
"""Optional JSON Schema for parameters. The hosted API doesn't use it yet:
|
|
27
|
+
arguments are passed through as the code gave them."""
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class CallbackRegistry:
|
|
31
|
+
"""A collection of callbacks, built with a decorator or ``add``.
|
|
32
|
+
|
|
33
|
+
Example:
|
|
34
|
+
callbacks = CallbackRegistry()
|
|
35
|
+
|
|
36
|
+
@callbacks.callback(description="Look up a user by id")
|
|
37
|
+
async def get_user(id: int) -> dict:
|
|
38
|
+
...
|
|
39
|
+
|
|
40
|
+
sandbox = Sandbox(callbacks=callbacks)
|
|
41
|
+
"""
|
|
42
|
+
|
|
43
|
+
def __init__(self) -> None:
|
|
44
|
+
self._callbacks: list[CallbackDict] = []
|
|
45
|
+
|
|
46
|
+
def callback(
|
|
47
|
+
self,
|
|
48
|
+
name: Optional[str] = None,
|
|
49
|
+
description: str = "",
|
|
50
|
+
schema: Optional[dict[str, Any]] = None,
|
|
51
|
+
) -> Callable[[F], F]:
|
|
52
|
+
"""Register the decorated function, named after it unless ``name`` is
|
|
53
|
+
given."""
|
|
54
|
+
|
|
55
|
+
def register(fn: F) -> F:
|
|
56
|
+
self.add(fn, name=name, description=description, schema=schema)
|
|
57
|
+
return fn
|
|
58
|
+
|
|
59
|
+
return register
|
|
60
|
+
|
|
61
|
+
def add(
|
|
62
|
+
self,
|
|
63
|
+
fn: Callable[..., Any],
|
|
64
|
+
name: Optional[str] = None,
|
|
65
|
+
description: str = "",
|
|
66
|
+
schema: Optional[dict[str, Any]] = None,
|
|
67
|
+
) -> None:
|
|
68
|
+
"""Register ``fn``, named after it unless ``name`` is given."""
|
|
69
|
+
entry: CallbackDict = {
|
|
70
|
+
"name": name or fn.__name__,
|
|
71
|
+
"fn": fn,
|
|
72
|
+
"description": description or inspect.getdoc(fn) or "",
|
|
73
|
+
}
|
|
74
|
+
if schema is not None:
|
|
75
|
+
entry["schema"] = schema
|
|
76
|
+
self._callbacks.append(entry)
|
|
77
|
+
|
|
78
|
+
def __len__(self) -> int:
|
|
79
|
+
return len(self._callbacks)
|
|
80
|
+
|
|
81
|
+
def __iter__(self) -> Iterator[CallbackDict]:
|
|
82
|
+
return iter(self._callbacks)
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
Callbacks = Union[CallbackRegistry, Sequence[CallbackDict]]
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def normalize(callbacks: Optional[Callbacks]) -> dict[str, CallbackDict]:
|
|
89
|
+
"""The callbacks by name, checking each has a name and a function."""
|
|
90
|
+
by_name: dict[str, CallbackDict] = {}
|
|
91
|
+
for callback in callbacks or ():
|
|
92
|
+
name, fn = callback.get("name"), callback.get("fn")
|
|
93
|
+
if not name or not callable(fn):
|
|
94
|
+
raise ValueError("each callback needs a 'name' and a callable 'fn'")
|
|
95
|
+
if name in by_name:
|
|
96
|
+
raise ValueError(f"callback {name!r} is defined twice")
|
|
97
|
+
by_name[name] = callback
|
|
98
|
+
return by_name
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
async def invoke(callback: CallbackDict, args: dict[str, Any]) -> Any:
|
|
102
|
+
"""Call ``callback`` with the code's keyword arguments. A sync function
|
|
103
|
+
runs in a thread, so a slow one doesn't hold up the connection."""
|
|
104
|
+
fn = callback["fn"]
|
|
105
|
+
if inspect.iscoroutinefunction(fn):
|
|
106
|
+
return await fn(**args)
|
|
107
|
+
result = await asyncio.to_thread(fn, **args)
|
|
108
|
+
if inspect.isawaitable(result):
|
|
109
|
+
result = await result
|
|
110
|
+
return result
|