shardflux 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.
Files changed (40) hide show
  1. shardflux-0.1.0/.gitignore +6 -0
  2. shardflux-0.1.0/LICENSE +202 -0
  3. shardflux-0.1.0/PKG-INFO +162 -0
  4. shardflux-0.1.0/README.md +137 -0
  5. shardflux-0.1.0/pyproject.toml +58 -0
  6. shardflux-0.1.0/src/shardflux/__init__.py +43 -0
  7. shardflux-0.1.0/src/shardflux/_cell.py +327 -0
  8. shardflux-0.1.0/src/shardflux/_client.py +311 -0
  9. shardflux-0.1.0/src/shardflux/_errors.py +111 -0
  10. shardflux-0.1.0/src/shardflux/_http.py +165 -0
  11. shardflux-0.1.0/src/shardflux/_models.py +83 -0
  12. shardflux-0.1.0/src/shardflux/_tokens.py +111 -0
  13. shardflux-0.1.0/src/shardflux/_version.py +1 -0
  14. shardflux-0.1.0/src/shardflux/_workspace.py +247 -0
  15. shardflux-0.1.0/src/shardflux/py.typed +0 -0
  16. shardflux-0.1.0/tests/__init__.py +0 -0
  17. shardflux-0.1.0/tests/conftest.py +111 -0
  18. shardflux-0.1.0/tests/fixtures/cell-exec-python.json +19 -0
  19. shardflux-0.1.0/tests/fixtures/cell-file-write.json +20 -0
  20. shardflux-0.1.0/tests/fixtures/operation-capacity-pending.json +54 -0
  21. shardflux-0.1.0/tests/fixtures/operation-failed.json +45 -0
  22. shardflux-0.1.0/tests/fixtures/operation-queued.json +37 -0
  23. shardflux-0.1.0/tests/fixtures/operation-running.json +37 -0
  24. shardflux-0.1.0/tests/fixtures/operation-succeeded.json +51 -0
  25. shardflux-0.1.0/tests/fixtures/sdk-me.json +27 -0
  26. shardflux-0.1.0/tests/fixtures/sdk-unauthenticated.json +16 -0
  27. shardflux-0.1.0/tests/fixtures/sdk-workspaces-list.json +60 -0
  28. shardflux-0.1.0/tests/fixtures/tool-token.json +24 -0
  29. shardflux-0.1.0/tests/fixtures/workspace-delete.json +84 -0
  30. shardflux-0.1.0/tests/fixtures/workspace-detail-running.json +55 -0
  31. shardflux-0.1.0/tests/fixtures/workspace-detail-suspended.json +55 -0
  32. shardflux-0.1.0/tests/fixtures/workspace-fork.json +109 -0
  33. shardflux-0.1.0/tests/fixtures/workspace-open-queued.json +106 -0
  34. shardflux-0.1.0/tests/fixtures/workspace-open-running.json +79 -0
  35. shardflux-0.1.0/tests/fixtures/workspace-resume.json +110 -0
  36. shardflux-0.1.0/tests/fixtures/workspace-suspend.json +82 -0
  37. shardflux-0.1.0/tests/fixtures/workspace-tool-token-not-running.json +22 -0
  38. shardflux-0.1.0/tests/test_cell.py +289 -0
  39. shardflux-0.1.0/tests/test_client.py +283 -0
  40. shardflux-0.1.0/tests/test_live.py +35 -0
@@ -0,0 +1,6 @@
1
+ .venv/
2
+ dist/
3
+ __pycache__/
4
+ .pytest_cache/
5
+ .ruff_cache/
6
+ .mypy_cache/
@@ -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.
@@ -0,0 +1,162 @@
1
+ Metadata-Version: 2.4
2
+ Name: shardflux
3
+ Version: 0.1.0
4
+ Summary: Python client for Shardflux: cloud computers for AI agents. Persistent workspaces you open by key, run commands in, suspend, resume and fork.
5
+ Project-URL: Homepage, https://shardflux.dev
6
+ Author: Shardflux
7
+ License-Expression: Apache-2.0
8
+ License-File: LICENSE
9
+ Keywords: agents,ai-agents,code-execution,microvm,sandbox,sdk,shardflux,workspace
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3 :: Only
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Programming Language :: Python :: 3.14
20
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
21
+ Classifier: Typing :: Typed
22
+ Requires-Python: >=3.10
23
+ Requires-Dist: httpx<1,>=0.27
24
+ Description-Content-Type: text/markdown
25
+
26
+ # shardflux
27
+
28
+ Python client for [Shardflux](https://shardflux.dev): cloud computers for AI agents.
29
+
30
+ Open a persistent workspace by key, run commands in it, read and write its files, suspend it when
31
+ idle, resume it later with its disk and memory intact, and fork it.
32
+
33
+ > **Early access.** Shardflux is in early access. The API is versioned (`/v1`), but this client is
34
+ > below 1.0: a minor release may contain breaking changes.
35
+
36
+ - Python 3.10 or later; one dependency (`httpx`).
37
+ - Typed (`py.typed`).
38
+ - Retries, idempotency keys, operation polling and tool-token refresh are handled for you.
39
+
40
+ ## Install
41
+
42
+ ```sh
43
+ pip install shardflux
44
+ ```
45
+
46
+ ## Quick start
47
+
48
+ Create a project API key in the Shardflux console (`sfk_<key id>_<secret>`). API keys are server
49
+ credentials; keep them out of client-side code.
50
+
51
+ ```python
52
+ from shardflux import Shardflux
53
+
54
+ sf = Shardflux() # reads SHARDFLUX_API_KEY; or Shardflux(api_key="...")
55
+
56
+ # Creates the workspace on first use; afterwards reconnects (or resumes) the same one.
57
+ ws = sf.open(key="customer-42/main", template="python-node-browser")
58
+
59
+ result = ws.exec("python3 -c 'print(40 + 2)'")
60
+ print(result.exit_code, result.stdout) # 0 42
61
+
62
+ ws.files.write("/home/user/notes.txt", "hello from Python\n")
63
+ print(ws.files.read_text("/home/user/notes.txt"))
64
+
65
+ ws.suspend()
66
+ ```
67
+
68
+ `open()` waits until the workspace is running. Opening the same key again never resets it: files,
69
+ installed packages and running processes are still there.
70
+
71
+ ## Configuration
72
+
73
+ | Argument | Environment variable | Default |
74
+ | --- | --- | --- |
75
+ | `api_key` | `SHARDFLUX_API_KEY` | required |
76
+ | `base_url` | `SHARDFLUX_API_URL` | `https://api.shardflux.dev` |
77
+ | `timeout` | | `30.0` seconds per request |
78
+ | `max_retries` | | `2` (safe or idempotent requests only) |
79
+ | `http_client` | | a new `httpx.Client` (pass your own for proxies or custom transports) |
80
+
81
+ `Shardflux` is a context manager (`with Shardflux() as sf: ...`); `close()` closes the HTTP client
82
+ it created.
83
+
84
+ ## Commands
85
+
86
+ ```python
87
+ r = ws.exec("pip install requests && python3 app.py", cwd="/home/user/project", env={"DEBUG": "1"}, timeout=600)
88
+ r = ws.exec(["python3", "-V"]) # a list runs as argv, without a shell
89
+
90
+ r.exit_code, r.stdout, r.stderr, r.timed_out, r.ok
91
+ ```
92
+
93
+ A string runs through `bash -lc`; a list runs as argv. `timeout` (seconds) is enforced inside the
94
+ workspace. Pass `on_output=lambda stream, chunk: ...` to receive output as it arrives. If the
95
+ connection drops, `exec` resumes the output from byte offsets; it never starts the command twice.
96
+ Ctrl-C cancels the command in the workspace.
97
+
98
+ ## Files
99
+
100
+ ```python
101
+ ws.files.write("/home/user/data.bin", b"\x00\x01\x02", create_parents=True)
102
+ data = ws.files.read("/home/user/data.bin") # bytes, the whole file
103
+ text = ws.files.read_text("/home/user/notes.txt")
104
+ ws.files.list("/home/user") # {"entries": [...], "truncated": False}
105
+ ws.files.stat("/home/user/notes.txt")
106
+ ws.files.remove("/home/user/data.bin")
107
+ ```
108
+
109
+ Writes are atomic and durable: they are acknowledged after the file and its directory are fsynced.
110
+
111
+ ## Lifecycle
112
+
113
+ ```python
114
+ ws.suspend(wait=True) # memory and processes are checkpointed
115
+ ws.resume(wait=True) # or open() the key again
116
+
117
+ copy = ws.fork("customer-42/experiment") # waits until the fork is running
118
+ copy.delete() # tool access ends at once; keys are never reused
119
+
120
+ for w in sf.workspaces.list_all(key_prefix="customer-42/"):
121
+ print(w.key, w.state)
122
+ page = sf.workspaces.list(limit=50) # page.data, page.next_cursor
123
+ ```
124
+
125
+ `suspend`, `resume`, `snapshot` and `delete` return the `Operation`; with `wait=True` they wait
126
+ for it to finish. Waiting polls with backoff (250 ms doubling to 5 s, ±20 % jitter). If `timeout`
127
+ (default 300 s) passes first, `OperationTimeoutError` is raised and the operation keeps running
128
+ server side: `sf.workspaces.wait_for_operation(err.operation_id)` waits again.
129
+
130
+ ## Errors
131
+
132
+ All errors derive from `ShardfluxError`.
133
+
134
+ - `ShardfluxApiError`: the API or the workspace refused the request. It mirrors the error
135
+ envelope: `code`, `message`, `request_id`, `retryable`, plus `status`, `details`,
136
+ `operation_id` and `retry_after`.
137
+ - `OperationFailedError`: an awaited operation ended `failed` or `canceled` (`error_code`,
138
+ `operation`).
139
+ - `OperationTimeoutError`: waiting gave up; the operation continues (`operation_id`).
140
+ - `ShardfluxProtocolError`: a response was not the documented shape.
141
+
142
+ ```python
143
+ from shardflux import ShardfluxApiError
144
+
145
+ try:
146
+ sf.open(key="customer-42/main", template="python-node-browser")
147
+ except ShardfluxApiError as err:
148
+ print(err.code, err.message, err.request_id, err.retryable)
149
+ ```
150
+
151
+ Treat unknown error codes as generic errors: show `message`, and use `retryable`.
152
+
153
+ ## Anything else
154
+
155
+ `sf.me()` returns the API key's organization and project. `sf.request(method, path, ...)` calls
156
+ any `/v1` route with the client's authentication, retries and error handling. The TypeScript SDK
157
+ (`npm install @shardflux/sdk`) covers the full API, including agent tool definitions for model
158
+ providers.
159
+
160
+ ## License
161
+
162
+ Apache-2.0
@@ -0,0 +1,137 @@
1
+ # shardflux
2
+
3
+ Python client for [Shardflux](https://shardflux.dev): cloud computers for AI agents.
4
+
5
+ Open a persistent workspace by key, run commands in it, read and write its files, suspend it when
6
+ idle, resume it later with its disk and memory intact, and fork it.
7
+
8
+ > **Early access.** Shardflux is in early access. The API is versioned (`/v1`), but this client is
9
+ > below 1.0: a minor release may contain breaking changes.
10
+
11
+ - Python 3.10 or later; one dependency (`httpx`).
12
+ - Typed (`py.typed`).
13
+ - Retries, idempotency keys, operation polling and tool-token refresh are handled for you.
14
+
15
+ ## Install
16
+
17
+ ```sh
18
+ pip install shardflux
19
+ ```
20
+
21
+ ## Quick start
22
+
23
+ Create a project API key in the Shardflux console (`sfk_<key id>_<secret>`). API keys are server
24
+ credentials; keep them out of client-side code.
25
+
26
+ ```python
27
+ from shardflux import Shardflux
28
+
29
+ sf = Shardflux() # reads SHARDFLUX_API_KEY; or Shardflux(api_key="...")
30
+
31
+ # Creates the workspace on first use; afterwards reconnects (or resumes) the same one.
32
+ ws = sf.open(key="customer-42/main", template="python-node-browser")
33
+
34
+ result = ws.exec("python3 -c 'print(40 + 2)'")
35
+ print(result.exit_code, result.stdout) # 0 42
36
+
37
+ ws.files.write("/home/user/notes.txt", "hello from Python\n")
38
+ print(ws.files.read_text("/home/user/notes.txt"))
39
+
40
+ ws.suspend()
41
+ ```
42
+
43
+ `open()` waits until the workspace is running. Opening the same key again never resets it: files,
44
+ installed packages and running processes are still there.
45
+
46
+ ## Configuration
47
+
48
+ | Argument | Environment variable | Default |
49
+ | --- | --- | --- |
50
+ | `api_key` | `SHARDFLUX_API_KEY` | required |
51
+ | `base_url` | `SHARDFLUX_API_URL` | `https://api.shardflux.dev` |
52
+ | `timeout` | | `30.0` seconds per request |
53
+ | `max_retries` | | `2` (safe or idempotent requests only) |
54
+ | `http_client` | | a new `httpx.Client` (pass your own for proxies or custom transports) |
55
+
56
+ `Shardflux` is a context manager (`with Shardflux() as sf: ...`); `close()` closes the HTTP client
57
+ it created.
58
+
59
+ ## Commands
60
+
61
+ ```python
62
+ r = ws.exec("pip install requests && python3 app.py", cwd="/home/user/project", env={"DEBUG": "1"}, timeout=600)
63
+ r = ws.exec(["python3", "-V"]) # a list runs as argv, without a shell
64
+
65
+ r.exit_code, r.stdout, r.stderr, r.timed_out, r.ok
66
+ ```
67
+
68
+ A string runs through `bash -lc`; a list runs as argv. `timeout` (seconds) is enforced inside the
69
+ workspace. Pass `on_output=lambda stream, chunk: ...` to receive output as it arrives. If the
70
+ connection drops, `exec` resumes the output from byte offsets; it never starts the command twice.
71
+ Ctrl-C cancels the command in the workspace.
72
+
73
+ ## Files
74
+
75
+ ```python
76
+ ws.files.write("/home/user/data.bin", b"\x00\x01\x02", create_parents=True)
77
+ data = ws.files.read("/home/user/data.bin") # bytes, the whole file
78
+ text = ws.files.read_text("/home/user/notes.txt")
79
+ ws.files.list("/home/user") # {"entries": [...], "truncated": False}
80
+ ws.files.stat("/home/user/notes.txt")
81
+ ws.files.remove("/home/user/data.bin")
82
+ ```
83
+
84
+ Writes are atomic and durable: they are acknowledged after the file and its directory are fsynced.
85
+
86
+ ## Lifecycle
87
+
88
+ ```python
89
+ ws.suspend(wait=True) # memory and processes are checkpointed
90
+ ws.resume(wait=True) # or open() the key again
91
+
92
+ copy = ws.fork("customer-42/experiment") # waits until the fork is running
93
+ copy.delete() # tool access ends at once; keys are never reused
94
+
95
+ for w in sf.workspaces.list_all(key_prefix="customer-42/"):
96
+ print(w.key, w.state)
97
+ page = sf.workspaces.list(limit=50) # page.data, page.next_cursor
98
+ ```
99
+
100
+ `suspend`, `resume`, `snapshot` and `delete` return the `Operation`; with `wait=True` they wait
101
+ for it to finish. Waiting polls with backoff (250 ms doubling to 5 s, ±20 % jitter). If `timeout`
102
+ (default 300 s) passes first, `OperationTimeoutError` is raised and the operation keeps running
103
+ server side: `sf.workspaces.wait_for_operation(err.operation_id)` waits again.
104
+
105
+ ## Errors
106
+
107
+ All errors derive from `ShardfluxError`.
108
+
109
+ - `ShardfluxApiError`: the API or the workspace refused the request. It mirrors the error
110
+ envelope: `code`, `message`, `request_id`, `retryable`, plus `status`, `details`,
111
+ `operation_id` and `retry_after`.
112
+ - `OperationFailedError`: an awaited operation ended `failed` or `canceled` (`error_code`,
113
+ `operation`).
114
+ - `OperationTimeoutError`: waiting gave up; the operation continues (`operation_id`).
115
+ - `ShardfluxProtocolError`: a response was not the documented shape.
116
+
117
+ ```python
118
+ from shardflux import ShardfluxApiError
119
+
120
+ try:
121
+ sf.open(key="customer-42/main", template="python-node-browser")
122
+ except ShardfluxApiError as err:
123
+ print(err.code, err.message, err.request_id, err.retryable)
124
+ ```
125
+
126
+ Treat unknown error codes as generic errors: show `message`, and use `retryable`.
127
+
128
+ ## Anything else
129
+
130
+ `sf.me()` returns the API key's organization and project. `sf.request(method, path, ...)` calls
131
+ any `/v1` route with the client's authentication, retries and error handling. The TypeScript SDK
132
+ (`npm install @shardflux/sdk`) covers the full API, including agent tool definitions for model
133
+ providers.
134
+
135
+ ## License
136
+
137
+ Apache-2.0
@@ -0,0 +1,58 @@
1
+ [build-system]
2
+ requires = ["hatchling>=1.27"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "shardflux"
7
+ dynamic = ["version"]
8
+ description = "Python client for Shardflux: cloud computers for AI agents. Persistent workspaces you open by key, run commands in, suspend, resume and fork."
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ license = "Apache-2.0"
12
+ license-files = ["LICENSE"]
13
+ authors = [{ name = "Shardflux" }]
14
+ keywords = ["shardflux", "agents", "ai-agents", "sandbox", "workspace", "microvm", "code-execution", "sdk"]
15
+ classifiers = [
16
+ "Development Status :: 3 - Alpha",
17
+ "Intended Audience :: Developers",
18
+ "Operating System :: OS Independent",
19
+ "Programming Language :: Python :: 3",
20
+ "Programming Language :: Python :: 3 :: Only",
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
+ "Programming Language :: Python :: 3.14",
26
+ "Topic :: Software Development :: Libraries :: Python Modules",
27
+ "Typing :: Typed",
28
+ ]
29
+ dependencies = ["httpx>=0.27,<1"]
30
+
31
+ [project.urls]
32
+ Homepage = "https://shardflux.dev"
33
+
34
+ [dependency-groups]
35
+ dev = ["pytest>=8", "ruff>=0.6"]
36
+
37
+ [tool.hatch.version]
38
+ path = "src/shardflux/_version.py"
39
+
40
+ [tool.hatch.build.targets.wheel]
41
+ packages = ["src/shardflux"]
42
+ core-metadata-version = "2.4"
43
+
44
+ [tool.hatch.build.targets.sdist]
45
+ include = ["src/shardflux", "tests", "README.md", "LICENSE", "pyproject.toml"]
46
+ core-metadata-version = "2.4"
47
+
48
+ [tool.pytest.ini_options]
49
+ testpaths = ["tests"]
50
+ addopts = "-q"
51
+
52
+ [tool.ruff]
53
+ line-length = 120
54
+ target-version = "py310"
55
+ src = ["src", "tests"]
56
+
57
+ [tool.ruff.lint]
58
+ select = ["E", "F", "W", "I", "UP", "B", "SIM", "RUF", "C4", "PT", "RET"]
@@ -0,0 +1,43 @@
1
+ """Python client for Shardflux: cloud computers for AI agents.
2
+
3
+ from shardflux import Shardflux
4
+
5
+ sf = Shardflux() # SHARDFLUX_API_KEY, optional SHARDFLUX_API_URL
6
+ ws = sf.open(key="customer-42/main", template="python-node-browser")
7
+ print(ws.exec("python3 -c 'print(40 + 2)'").stdout)
8
+ ws.files.write("/home/user/notes.txt", "hello\\n")
9
+ ws.suspend()
10
+ """
11
+
12
+ from ._cell import CellClient
13
+ from ._client import DEFAULT_BASE_URL, Shardflux, WorkspacesApi
14
+ from ._errors import (
15
+ OperationFailedError,
16
+ OperationTimeoutError,
17
+ ShardfluxApiError,
18
+ ShardfluxError,
19
+ ShardfluxProtocolError,
20
+ )
21
+ from ._models import ExecResult, Operation, Page
22
+ from ._tokens import ToolTokenManager
23
+ from ._version import __version__
24
+ from ._workspace import Files, Workspace
25
+
26
+ __all__ = [
27
+ "DEFAULT_BASE_URL",
28
+ "CellClient",
29
+ "ExecResult",
30
+ "Files",
31
+ "Operation",
32
+ "OperationFailedError",
33
+ "OperationTimeoutError",
34
+ "Page",
35
+ "Shardflux",
36
+ "ShardfluxApiError",
37
+ "ShardfluxError",
38
+ "ShardfluxProtocolError",
39
+ "ToolTokenManager",
40
+ "Workspace",
41
+ "WorkspacesApi",
42
+ "__version__",
43
+ ]