sandscale 1.0.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 (39) hide show
  1. sandscale-1.0.0/.gitignore +8 -0
  2. sandscale-1.0.0/LICENSE +231 -0
  3. sandscale-1.0.0/PKG-INFO +416 -0
  4. sandscale-1.0.0/README.md +387 -0
  5. sandscale-1.0.0/pyproject.toml +73 -0
  6. sandscale-1.0.0/src/sandscale/__init__.py +450 -0
  7. sandscale-1.0.0/src/sandscale/_account.py +150 -0
  8. sandscale-1.0.0/src/sandscale/_admin.py +349 -0
  9. sandscale-1.0.0/src/sandscale/_api.py +291 -0
  10. sandscale-1.0.0/src/sandscale/_api_gen.py +353 -0
  11. sandscale-1.0.0/src/sandscale/_builtin.py +20 -0
  12. sandscale-1.0.0/src/sandscale/_call.py +80 -0
  13. sandscale-1.0.0/src/sandscale/_capabilities.py +177 -0
  14. sandscale-1.0.0/src/sandscale/_code.py +340 -0
  15. sandscale-1.0.0/src/sandscale/_compute.py +131 -0
  16. sandscale-1.0.0/src/sandscale/_objects.py +193 -0
  17. sandscale-1.0.0/src/sandscale/_operations_gen.py +355 -0
  18. sandscale-1.0.0/src/sandscale/_processes.py +40 -0
  19. sandscale-1.0.0/src/sandscale/_services.py +1104 -0
  20. sandscale-1.0.0/src/sandscale/_transport.py +371 -0
  21. sandscale-1.0.0/src/sandscale/_version.py +5 -0
  22. sandscale-1.0.0/src/sandscale/admin_models.py +1663 -0
  23. sandscale-1.0.0/src/sandscale/errors.py +394 -0
  24. sandscale-1.0.0/src/sandscale/integrations/__init__.py +13 -0
  25. sandscale-1.0.0/src/sandscale/integrations/langchain.py +243 -0
  26. sandscale-1.0.0/src/sandscale/integrations/openai_agents.py +381 -0
  27. sandscale-1.0.0/src/sandscale/models.py +566 -0
  28. sandscale-1.0.0/src/sandscale/py.typed +0 -0
  29. sandscale-1.0.0/tests/__init__.py +2 -0
  30. sandscale-1.0.0/tests/mock_server.py +122 -0
  31. sandscale-1.0.0/tests/test_agent.py +149 -0
  32. sandscale-1.0.0/tests/test_call.py +65 -0
  33. sandscale-1.0.0/tests/test_client.py +640 -0
  34. sandscale-1.0.0/tests/test_code_mode.py +336 -0
  35. sandscale-1.0.0/tests/test_integration.py +32 -0
  36. sandscale-1.0.0/tests/test_integrations.py +206 -0
  37. sandscale-1.0.0/tests/test_integrations_live.py +103 -0
  38. sandscale-1.0.0/tests/test_parity.py +706 -0
  39. sandscale-1.0.0/tests/test_routes.py +391 -0
@@ -0,0 +1,8 @@
1
+ node_modules/
2
+ dist/
3
+ __pycache__/
4
+ *.egg-info/
5
+ .venv/
6
+ .pytest_cache/
7
+ .mypy_cache/
8
+ .DS_Store
@@ -0,0 +1,231 @@
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 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 [yyyy] [name of copyright owner]
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.
202
+
203
+ --------------------------------------------------------------------------------
204
+
205
+ Copyright 2009 The Go Authors.
206
+
207
+ Redistribution and use in source and binary forms, with or without
208
+ modification, are permitted provided that the following conditions are
209
+ met:
210
+
211
+ * Redistributions of source code must retain the above copyright
212
+ notice, this list of conditions and the following disclaimer.
213
+ * Redistributions in binary form must reproduce the above
214
+ copyright notice, this list of conditions and the following disclaimer
215
+ in the documentation and/or other materials provided with the
216
+ distribution.
217
+ * Neither the name of Google LLC nor the names of its
218
+ contributors may be used to endorse or promote products derived from
219
+ this software without specific prior written permission.
220
+
221
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
222
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
223
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
224
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
225
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
226
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
227
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
228
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
229
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
230
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
231
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,416 @@
1
+ Metadata-Version: 2.4
2
+ Name: sandscale
3
+ Version: 1.0.0
4
+ Summary: Sandscale Python SDK: sandboxes, workspaces and build hosts over the Sandscale API
5
+ Project-URL: Homepage, https://github.com/sandscale/sandscale-python#readme
6
+ Project-URL: Issues, https://github.com/sandscale/sandscale-python/issues
7
+ Project-URL: Source, https://github.com/sandscale/sandscale-python
8
+ Project-URL: Changelog, https://github.com/sandscale/sandscale-python/blob/main/CHANGELOG.md
9
+ Author: Neural Inverse
10
+ License-Expression: Apache-2.0
11
+ License-File: LICENSE
12
+ Keywords: agents,ai,code-execution,sandbox,sandscale
13
+ Classifier: Development Status :: 3 - Alpha
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Typing :: Typed
17
+ Requires-Python: >=3.10
18
+ Requires-Dist: httpx>=0.24
19
+ Provides-Extra: dev
20
+ Requires-Dist: build>=1.2; extra == 'dev'
21
+ Requires-Dist: mypy>=1.13; extra == 'dev'
22
+ Requires-Dist: pytest>=7.0; extra == 'dev'
23
+ Provides-Extra: langchain
24
+ Requires-Dist: deepagents>=0.7; extra == 'langchain'
25
+ Requires-Dist: langchain-core>=1.0; extra == 'langchain'
26
+ Provides-Extra: openai-agents
27
+ Requires-Dist: openai-agents>=0.26; extra == 'openai-agents'
28
+ Description-Content-Type: text/markdown
29
+
30
+ <!-- Copyright 2026 Neural Inverse -->
31
+ <!-- SPDX-License-Identifier: Apache-2.0 -->
32
+
33
+ # sandscale
34
+
35
+ Python SDK for [Sandscale](https://sandscale.dev): sandboxes, workspaces and build hosts over
36
+ the Sandscale API (`https://api.sandscale.dev`). One dependency (`httpx`); Python 3.10 or later.
37
+
38
+ The server decides everything: permissions, plan limits, quotas, entitlements, kill switches
39
+ and regions. The SDK sends your request as you (your API key or your own sign-in token) and
40
+ hands back the server's answer, including its error code and message.
41
+
42
+ ```bash
43
+ pip install sandscale
44
+ ```
45
+
46
+ ## Quick start
47
+
48
+ ```python
49
+ import sys
50
+ from sandscale import Sandscale
51
+
52
+ with Sandscale() as sandscale: # SANDSCALE_API_KEY from the environment
53
+ box = sandscale.sandboxes.create(template="builtin:python", timeout_seconds=600)
54
+ # BUILTIN_TEMPLATES lists the built-ins: base (default), python, node, go, go_postgres (Go with PostgreSQL 17
55
+ # running on 127.0.0.1:5432, TEST_DATABASE_URL set), minimal. The default image has
56
+ # Python 3 with pip, Node.js with npm, git, curl, a C compiler, jq and unzip (docs/sandbox/images.md).
57
+ try:
58
+ run = sandscale.sandboxes.run(
59
+ box.id,
60
+ 'python -c "print(6*7)"',
61
+ region=box.region,
62
+ on_stdout=sys.stdout.write,
63
+ on_stderr=sys.stderr.write,
64
+ )
65
+ print("exit code", run.exit_code)
66
+ finally:
67
+ sandscale.sandboxes.stop(box.id, region=box.region)
68
+ ```
69
+
70
+ ## Authentication
71
+
72
+ | Argument | Environment | |
73
+ |---|---|---|
74
+ | `api_key` | `SANDSCALE_API_KEY` | A Sandscale API key. |
75
+ | `token` | | The person's own sign-in access token, or a function returning a current one (called before every request, so it can refresh). |
76
+ | `org_id` | `SANDSCALE_ORG_ID` | Sent as `X-Org-ID`; required by workspace and build host calls, whose routes name the organization. |
77
+ | `base_url` | `SANDSCALE_BASE_URL` | Default `https://api.sandscale.dev`. `https` only (plain `http` only to a loopback host). |
78
+
79
+ Credentials are held in memory and sent only to the configured API origin and the region
80
+ origins the server lists; redirects are not followed, so a credential never follows one.
81
+
82
+ ## Regions
83
+
84
+ One account works in every Sandscale region. Pass `region="us"` or `region="eu"` to the client
85
+ (the default for every call) or to any call:
86
+
87
+ | Region | API |
88
+ |---|---|
89
+ | none | `https://api.sandscale.dev`, the front door: it routes to the request's region, US by default |
90
+ | `"us"` | `https://api.us.sandscale.dev` |
91
+ | `"eu"` | `https://api.sandscale.dev` with `region=eu1`: the front door sends the call to the EU region with your own credential. The EU regional host (`api.eu.sandscale.dev`) does not accept a global API key or sign-in token, so the SDK never calls it directly |
92
+
93
+ A region id such as `us1` names the same region. `region_urls` sets origins explicitly.
94
+ Against another `base_url` (a self-hosted Sandscale) a region is looked up in that server's
95
+ public region list (`GET /api/v1/regions`).
96
+
97
+ Models carry the `region` they were read from; pass it to later calls on them. Lists without a
98
+ region read every Sandscale region the front door reports live and merge the results; `pages`
99
+ says, per region, the next cursor or the error that region answered.
100
+
101
+ ## API
102
+
103
+ | Area | Methods |
104
+ |---|---|
105
+ | `sandboxes` | `create`, `get`, `list`, `run` (live stdout and stderr, exit code), `logs`, `write_file`, `read_file`, `list_files`, `pause`, `resume`, `snapshot`, `list_snapshots`, `stop`, `attach_volume`, `list_attachments`, `commit_volume`, `detach_volume`, `restore_cache`, `save_cache` |
106
+ | `volumes` | `create`, `get`, `list`, `delete` |
107
+ | `caches` | `list`, `delete` |
108
+ | `workspaces` | `list`, `get`, `start`, `stop`, `connect_info` |
109
+ | `build_hosts` | `list_pools`, `list`, `get`, `start` (take a lease of a pool), `stop` (release it), `connect_info`, `ssh_certificate` |
110
+ | `sandboxes` | `create` (`network`, `image`, `runtime`, `environment_id`), `get`, `list`, `run` (live stdout and stderr, exit code), `logs`, `write_file`, `read_file`, `list_files`, `pause`, `resume`, `snapshot`, `list_snapshots`, `stop`, `expose_port`, `list_ports`, `close_port`, `create_preview_link`, `list_preview_links`, `revoke_preview_link`, `ssh_info`, `ssh_certificate` |
111
+ | `snapshots` | `list` (with quota usage), `get`, `delete` |
112
+ | `templates` | `create`, `list`, `get`, `delete`, `build_status` |
113
+ | `policy` | `get`, `set` |
114
+ | `webhooks` | `list`, `create`, `delete`, `verify` (also `verify_webhook_signature`) |
115
+ | `traces` | `list`, `get`, `get_export`, `set_export`, `delete_export`, `test_export` |
116
+ | `execute`, `search`, `tasks`, `code_policy` | code mode (below): `tasks.get`, `tasks.wait`, `code_policy.get`, `code_policy.set` |
117
+ | `api` | the typed API (below): every operation as `api.<namespace>.<function>(**args)` |
118
+ | `objects` | buckets (`create_bucket`, `list_buckets`, `get_bucket`, `update_bucket`, `delete_bucket`), lifecycle, policy, access keys, `limits` |
119
+ | `workspaces` | `list`, `get`, `start`, `stop`, `connect_info`, `create`, `update`, `delete`, `rebuild`, `open_link`, `list_backups`, `create_backup`, `verify_backup`, `list_apps`, `share_app` |
120
+ | `build_hosts` | `list_pools`, `list`, `get`, `start` (take a lease of a pool), `stop` (release it), `connect_info`, `ssh_certificate`, `renew`, `kill`, `list_runs`, `get_run`, `list_artifacts`, `get_artifact`, `download_artifact`, `delete_artifact`, `list_caches`, `list_pool_caches`, `purge_pool_cache` |
121
+ | `lab_hosts` | `list`, `get`, `revoke` |
122
+ | `agent_cloud` | `create_task`, `list_tasks`, `get_task`, `cancel_task` |
123
+ | `account` | `billing`, `change_plan`, `set_overage`, `cancel_pending_plan_change`, `checkout`, `usage`, `regions`, `list_api_keys`, `create_api_key`, `rotate_api_key`, `delete_api_key` |
124
+
125
+ `sandboxes.run` waits for the command and returns a `RunResult` (`run_id`, `exit_code`,
126
+ `stdout`, `stderr`, `duration_ms`, `oom_killed`, `timed_out`, `streamed`). With `on_stdout` /
127
+ `on_stderr` it starts the command without waiting (`wait` false): the server answers with the
128
+ run's id, and the output arrives live, in the calling thread, from that run's log stream, after
129
+ the organization's DLP rules. The server may redact it, or end the stream with
130
+ `dlp_unavailable`, raised as a `ServerError`. The exit code comes from the stream's end. A
131
+ server that answers with the finished result instead gets the callbacks the final output once.
132
+
133
+ `sandboxes.create(vault_env=[VaultEnvRef("DB_PASSWORD", "secret/data/db", "password")])` puts
134
+ Sandscale Vault values in the sandbox's environment. The server reads them as you and gives them
135
+ to the sandbox only.
136
+
137
+ Persistent volumes keep a directory between sandboxes, in versions.
138
+ `attach_volume(sandbox_id, volume_id, mount_path, mode="rw")` mounts one (read-write by one
139
+ sandbox at a time, else 409 `volume_writer_attached`; `mode="ro"` is never written back),
140
+ `commit_volume` writes the next version and `detach_volume(..., commit=False)` drops
141
+ uncommitted changes (a read-write attachment commits first by default). Dependency caches are
142
+ keyed by the server from the lockfile it reads in the sandbox and shared within the organization
143
+ only:
144
+
145
+ ```python
146
+ r = sandscale.sandboxes.restore_cache(box.id, ecosystem="pip", lockfile="/workspace/requirements.txt")
147
+ if not r.hit:
148
+ sandscale.sandboxes.run(box.id, "pip install -r /workspace/requirements.txt")
149
+ sandscale.sandboxes.save_cache(box.id, ecosystem="pip", lockfile="/workspace/requirements.txt")
150
+ ```
151
+
152
+ ## More examples
153
+
154
+ Every call takes `region=` like the first ones. The server decides what you may do; the SDK
155
+ only carries the answer.
156
+
157
+ ### Ports, preview links and SSH
158
+
159
+ ```python
160
+ box = sandscale.sandboxes.create(template="builtin:python", network="allowlist", runtime="firecracker")
161
+ port = sandscale.sandboxes.expose_port(box.id, 8080, ttl_seconds=3600, region=box.region)
162
+ link = sandscale.sandboxes.create_preview_link(box.id, 8080, visibility="team", region=box.region)
163
+ print(link.url)
164
+ sandscale.sandboxes.revoke_preview_link(box.id, link.id, region=box.region)
165
+ sandscale.sandboxes.close_port(box.id, 8080, region=box.region)
166
+
167
+ cert = sandscale.sandboxes.ssh_certificate(box.id, open("id_ed25519.pub").read().strip(), region=box.region)
168
+ print(cert.known_hosts, cert.key_id) # the certificate itself is in cert.certificate
169
+ ```
170
+
171
+ ### Snapshots, templates and policy
172
+
173
+ ```python
174
+ snaps = sandscale.snapshots.list()
175
+ print(snaps.usage.count, snaps.usage.bytes)
176
+
177
+ tpl = sandscale.templates.create(name="py-ml", image="registry.example/py-ml@sha256:" + "0" * 64, memory_mb=2048)
178
+ print(sandscale.templates.build_status(tpl.id).status)
179
+
180
+ sandscale.policy.set(egress_allowlist=["pypi.org"], egress_presets=["npm", "pypi"], max_concurrent=10)
181
+ ```
182
+
183
+ `policy.set(hibernation="on" | "off" | "default")` sets hibernation between tool calls;
184
+ `keep_awake` retries a waking sandbox (`SandboxWakingError`) before raising.
185
+
186
+ ### Webhooks
187
+
188
+ ```python
189
+ from sandscale import verify_webhook_signature
190
+
191
+ hook = sandscale.webhooks.create(url="https://example.com/hooks/sandscale", events=["run.completed"])
192
+ signing_secret = hook.secret # shown once: store it in your secret manager, never print it
193
+
194
+ # In your receiver: pass the raw body exactly as received.
195
+ ok = verify_webhook_signature(request.headers.get("X-Sandscale-Signature"), raw_body, signing_secret)
196
+ ```
197
+
198
+ The signature is `sha256=` and the hex HMAC-SHA256 of the raw body under the secret; the check
199
+ is constant time. Current signing carries no timestamp. Test, redeliver and the delivery log
200
+ are not served yet.
201
+
202
+ ### Run traces and OpenTelemetry export
203
+
204
+ ```python
205
+ for t in sandscale.traces.list(limit=10).data:
206
+ print(t.trace_id, t.status, t.spans)
207
+ trace = sandscale.traces.get(t.trace_id)
208
+ sandscale.traces.set_export(protocol="otlp_http", endpoint="https://otel.example.com", headers={"x-honeycomb-team": api_key_for_collector})
209
+ print(sandscale.traces.test_export().ok)
210
+ ```
211
+
212
+ ### Object storage
213
+
214
+ ```python
215
+ from sandscale import LifecycleRule
216
+
217
+ sandscale.objects.create_bucket("artifacts", versioning="Enabled")
218
+ sandscale.objects.put_lifecycle("artifacts", [LifecycleRule(id="tmp", prefix="tmp/", expiration_days=7)])
219
+ created = sandscale.objects.create_access_key(description="ci", buckets=["artifacts"], expires_in_days=30)
220
+ key_id = created.access_key.access_key_id
221
+ secret = created.secret_access_key # shown once, not in repr(); store it, never log it
222
+ ```
223
+
224
+ ### Workspaces, build hosts and lab hosts
225
+
226
+ ```python
227
+ ws, build = sandscale.workspaces.create(name="dev", template_id="tpl-1", repository="github.com/acme/app")
228
+ print(sandscale.workspaces.open_link(ws.id, "vscode").url)
229
+ backup = sandscale.workspaces.create_backup(ws.id)
230
+ print(sandscale.workspaces.verify_backup(backup.id).valid)
231
+ sandscale.workspaces.share_app(ws.id, "web", "org")
232
+
233
+ lease = sandscale.build_hosts.renew("lease-1", 3600)
234
+ for artifact in sandscale.build_hosts.list_artifacts(lease.id):
235
+ data = sandscale.build_hosts.download_artifact(lease.id, artifact.id)
236
+ print(sandscale.build_hosts.list_pool_caches("pool-1").used_bytes)
237
+ sandscale.lab_hosts.revoke("host-1", reason="decommissioned")
238
+ ```
239
+
240
+ ### Agent Cloud tasks
241
+
242
+ ```python
243
+ task = sandscale.agent_cloud.create_task(repository="github.com/acme/app", brief="Fix the flaky test", engine="claude_code")
244
+ print(sandscale.agent_cloud.get_task(task.id).state)
245
+ sandscale.agent_cloud.cancel_task(task.id)
246
+ ```
247
+
248
+ These are Sandscale's lead routes (never the device agent). They need a signed-in person's
249
+ `token`; an API key is refused with 403 `person_required`.
250
+
251
+ ### Account
252
+
253
+ ```python
254
+ billing = sandscale.account.billing()
255
+ print(billing.state.plan, billing.balance.remaining_vcpu_hours)
256
+ sandscale.account.set_overage(True) # the server decides whether the plan allows it
257
+ sandscale.account.change_plan(plan="team", interval="month", seats=3)
258
+ print(sandscale.account.usage().running_boxes, [r.id for r in sandscale.account.regions()])
259
+
260
+ from datetime import datetime, timedelta, timezone
261
+ key = sandscale.account.create_api_key(name="ci", expires_at=datetime.now(timezone.utc) + timedelta(days=30))
262
+ new_key = key.key # shown once; store it, never print it
263
+ sandscale.account.rotate_api_key(key.id, overlap_seconds=300)
264
+ sandscale.account.delete_api_key(key.id)
265
+ ```
266
+
267
+ Plan changes, overage and personal API keys need a signed-in person's token. Secrets the server
268
+ shows once (webhook signing secret, `secret_access_key`, API key `key`) are fields excluded from
269
+ `repr` and from `raw`; the SDK never logs or prints them.
270
+
271
+ ## Agent frameworks
272
+
273
+ **LangChain.** `pip install "sandscale[langchain]"`. `SandscaleSandbox` is a Deep Agents sandbox
274
+ backend (its file tools and `execute` run in the sandbox; paths are absolute), and `SandscaleToolkit`
275
+ gives any LangChain agent `sandscale_run`, `sandscale_write_file` and `sandscale_read_file`:
276
+
277
+ ```python
278
+ from deepagents import create_deep_agent
279
+ from sandscale.integrations.langchain import SandscaleSandbox, SandscaleToolkit
280
+
281
+ with SandscaleSandbox.create(template="builtin:python", timeout_seconds=900) as backend:
282
+ agent = create_deep_agent(model="anthropic:claude-sonnet-4-6", backend=backend)
283
+
284
+ with SandscaleToolkit.create(template="builtin:node") as toolkit:
285
+ tools = toolkit.get_tools()
286
+ ```
287
+
288
+ **OpenAI Agents SDK.** `pip install "sandscale[openai-agents]"`. `SandscaleSandboxClient` runs a
289
+ `SandboxAgent`'s workspace in a sandbox (root `/workspace`; saved workspaces are tar archives; an
290
+ exposed port is published as a public preview link, Pro and up):
291
+
292
+ ```python
293
+ from agents.run import RunConfig
294
+ from agents.sandbox import SandboxRunConfig
295
+ from sandscale.integrations.openai_agents import SandscaleSandboxClient, SandscaleSandboxClientOptions
296
+
297
+ config = RunConfig(sandbox=SandboxRunConfig(
298
+ client=SandscaleSandboxClient(),
299
+ options=SandscaleSandboxClientOptions(template="builtin:python", timeout_seconds=900),
300
+ ))
301
+ ```
302
+
303
+ A sandbox an adapter started is stopped when it closes; one you pass in is left running. Both wait out
304
+ rate limits (429) and move files as streamed transfers (`sandboxes.upload` and `sandboxes.download`,
305
+ up to 1 GiB). Full scripts: `examples/langchain_deep_agent.py`, `examples/openai_agents_sandbox.py`.
306
+
307
+ ## For agents
308
+
309
+ ```python
310
+ c = sandscale.capabilities() # plan, limits, templates, regions, vCPU-hour balance and its reset time
311
+ box = sandscale.sandboxes.create(template="builtin:base", idempotency_key="job-42") # a retry never makes a second box
312
+ proc = sandscale.sandboxes.start_process(box.id, "python -m http.server 8000")
313
+ sandscale.sandboxes.wait_for_port(box.id, 8000)
314
+ log = sandscale.sandboxes.process_logs(box.id, proc.process_id, offset=0) # log.next_offset continues
315
+ sandscale.sandboxes.kill_process(box.id, proc.process_id)
316
+ text = sandscale.sandboxes.read_text(box.id, "/workspace/out.txt")
317
+ ```
318
+
319
+ A refused call raises an error whose `details` carry the next step the server names (the templates to start,
320
+ the plan that lifts a limit, when the allowance renews).
321
+
322
+ ## Code mode
323
+
324
+ `execute` runs a TypeScript or JavaScript script on the server against your typed API, as you: one
325
+ request instead of one per call. The script sees `sandscale.<namespace>.<fn>(args)` and
326
+ `vault.ref("store/name#field")`, may `await` and `return`, and its return value is `task.result`.
327
+
328
+ ```python
329
+ task = sandscale.execute("""
330
+ const box = await sandscale.sandbox.create({ template: "builtin:python" });
331
+ console.log("started", box.id);
332
+ return box.id;
333
+ """)
334
+ print(task.state, task.result, [line.text for line in task.console])
335
+ ```
336
+
337
+ The server answers within `wait_seconds` (at most 30); after a 202 the SDK reads the task again
338
+ (`poll_interval`, `timeout`) until it succeeded or failed. A failed task raises `TaskFailedError`
339
+ (its `code` is the task's: `script_error`, `syntax_error`, `time_limit` and so on; `task.error`
340
+ has the script `line` and `column` and the `api_error` that ended it, with its `next` step);
341
+ `raise_on_failure=False` returns it instead. A `timeout` that passes first raises
342
+ `TaskTimeoutError` while the task keeps running on the server.
343
+
344
+ A call the Organization's ask-first policy names waits for a person: `execute` returns the task in
345
+ state `awaiting_approval` with `pending_approval` (`request_id`, `operation`, `seq`), unless
346
+ `wait_for_approval=True`. Read it later with `sandscale.tasks.get(task_id, wait_seconds=30)` or
347
+ `sandscale.tasks.wait(task_id)`; reading an approved task resumes it. Only the person who started a
348
+ task reads it (anyone else gets `NotFoundError`).
349
+
350
+ ```python
351
+ found = sandscale.search('return api.find("snapshot a sandbox", 5)') # the typed API as data
352
+ print(found.result)
353
+ sandscale.code_policy.get().ask_first # e.g. ["destructive"]
354
+ sandscale.code_policy.set(["sandbox_terminate", "writes"]) # needs sandboxes:write
355
+ ```
356
+
357
+ ## Typed API
358
+
359
+ `sandscale.api.<namespace>.<function>(**args)` calls any operation of the typed API (the same
360
+ functions a code mode script calls) directly from Python. It is built at import from the generated
361
+ operation table; names work in camelCase and snake_case (`api.auditLogs.auditEventsList` and
362
+ `api.audit_logs.audit_events_list`), and `api.call("sandbox_snapshot_create", {...})` takes the
363
+ operation name.
364
+
365
+ ```python
366
+ snap = sandscale.api.sandbox.snapshot_create(id=box.id, label="before", region="us")
367
+ events = sandscale.api.audit_logs.audit_events_list(from_="2026-11-01", limit=50) # from_ for from
368
+ sandscale.api.sandbox.instances_ports_delete(id=box.id, port=8080, confirm=True)
369
+ ```
370
+
371
+ Arguments are the operation's parameter names; one the operation does not take, or a missing
372
+ required one, raises `ApiArgumentError` before any request. Organization path parameters are filled
373
+ from the client's `org_id`. An operation that deletes, ends or changes billing needs `confirm=True`
374
+ (never sent); without it the SDK raises `SandscaleError` with code `confirmation_required` and sends
375
+ nothing. A write takes `idempotency_key` (sent as `Idempotency-Key`, so it is retried like a read).
376
+ Answers are the server's JSON as is; refusals are the usual errors below.
377
+
378
+ ## Errors
379
+
380
+ Every API error is a `SandscaleError` with the server's `status`, `code`, `message`,
381
+ `request_id` and `details`: `InvalidRequestError` (400, 413, 422), `AuthenticationError` (401),
382
+ `PermissionDeniedError` (403), `NotFoundError` (404), `ConflictError` (409),
383
+ `LimitExceededError` (402 or a quota or limit code, including `lease_duration_limit`, `lease_vcpu_limit`, `lease_concurrent_limit`, `lab_host_limit`, `vault_secret_limit` and `vault_store_limit`, whose `details` carry `plan` and the limit hit) and its `RateLimitError` (429, with
384
+ `retry_after`), `EntitlementError` (`not_entitled`, `payment_required`, `entitlement_*`,
385
+ `plan_*`, `*_not_in_plan`; `lease_not_in_plan` now means a misconfigured plan), `RegionError` (`wrong_region` with `region`, `region_*`), `KillSwitchError`
386
+ (`kill_switch_*`), `ServerError` (5xx; `retryable` for 502, 503 and 504) with `ServiceUnavailableError` (any 503, with
387
+ `retry_after`; also `entitlement_unavailable`) and `SandboxWakingError` (503 `sandbox_waking`: the
388
+ sandbox is resuming, retry after `retry_after`), and `APIConnectionError` (no answer).
389
+ `ConfigurationError` is raised before any request when the client cannot be configured safely.
390
+
391
+ ## Retries
392
+
393
+ Only safe calls (`GET`) are retried, at most `max_retries` times (default 2), after a
394
+ connection error, 429, 502, 503 or 504, with exponential backoff and full jitter (at most 8 s),
395
+ or the server's `Retry-After` (at most 60 s). Kill switch, entitlement and region refusals are
396
+ never retried. Calls that change something are sent once.
397
+
398
+ ## Known gaps
399
+
400
+ - **Cross-region credentials.** Until the global plane syncs API keys and sign-in sessions to
401
+ every region, a credential of one region is refused in another with `wrong_region`
402
+ (`RegionError`, with `region`).
403
+ - **Vault environment on sandboxes** needs a server with `vault_env`
404
+ (docs/sandbox/vault-env.md in the Sandscale documentation). A server from before it ignores the
405
+ field.
406
+ - Synchronous client only; an asyncio client is a follow-up.
407
+
408
+ ## Tests
409
+
410
+ ```bash
411
+ pip install -e ".[dev]" && pytest # unit tests against a local mock server, route contract
412
+ SANDSCALE_API_KEY=... pytest # also the integration test (starts and stops one sandbox)
413
+ ```
414
+
415
+ `tests/test_routes.py` fails when the server stops mounting a route this SDK calls (the route
416
+ inventory of the Sandscale repository) or when the SDK calls a route it does not list.