boxrouter 0.0.1a2__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.
@@ -0,0 +1,89 @@
1
+ # PolyForm Shield License 1.0.0
2
+
3
+ <https://polyformproject.org/licenses/shield/1.0.0>
4
+
5
+ ## Acceptance
6
+
7
+ In order to get any license under these terms, you must agree to them as both strict obligations and conditions to all your licenses.
8
+
9
+ ## Copyright License
10
+
11
+ The licensor grants you a copyright license for the software to do everything you might do with the software that would otherwise infringe the licensor's copyright in it for any permitted purpose. However, you may only distribute the software according to [Distribution License](#distribution-license) and make changes or new works based on the software according to [Changes and New Works License](#changes-and-new-works-license).
12
+
13
+ ## Distribution License
14
+
15
+ The licensor grants you an additional copyright license to distribute copies of the software. Your license to distribute covers distributing the software with changes and new works permitted by [Changes and New Works License](#changes-and-new-works-license).
16
+
17
+ ## Notices
18
+
19
+ You must ensure that anyone who gets a copy of any part of the software from you also gets a copy of these terms or the URL for them above, as well as copies of any plain-text lines beginning with `Required Notice:` that the licensor provided with the software. For example:
20
+
21
+ > Required Notice: Copyright Yoyodyne, Inc. (http://example.com)
22
+
23
+ ## Changes and New Works License
24
+
25
+ The licensor grants you an additional copyright license to make changes and new works based on the software for any permitted purpose.
26
+
27
+ ## Patent License
28
+
29
+ The licensor grants you a patent license for the software that covers patent claims the licensor can license, or becomes able to license, that you would infringe by using the software.
30
+
31
+ ## Noncompete
32
+
33
+ Any purpose is a permitted purpose, except for providing any product that competes with the software or any product the licensor or any of its affiliates provides using the software.
34
+
35
+ ## Competition
36
+
37
+ Goods and services compete even when they provide functionality through different kinds of interfaces or for different technical platforms. Applications can compete with services, libraries with plugins, frameworks with development tools, and so on, even if they're written in different programming languages or for different computer architectures. Goods and services compete even when provided free of charge. If you market a product as a practical substitute for the software or another product, it definitely competes.
38
+
39
+ ## New Products
40
+
41
+ If you are using the software to provide a product that does not compete, but the licensor or any of its affiliates brings your product into competition by providing a new version of the software or another product using the software, you may continue using versions of the software available under these terms beforehand to provide your competing product, but not any later versions.
42
+
43
+ ## Discontinued Products
44
+
45
+ You may begin using the software to compete with a product or service that the licensor or any of its affiliates has stopped providing, unless the licensor includes a plain-text line beginning with `Licensor Line of Business:` with the software that mentions that line of business. For example:
46
+
47
+ > Licensor Line of Business: YoyodyneCMS Content Management System (http://example.com/cms)
48
+
49
+ ## Sales of Business
50
+
51
+ If the licensor or any of its affiliates sells a line of business developing the software or using the software to provide a product, the buyer can also enforce [Noncompete](#noncompete) for that product.
52
+
53
+ ## Fair Use
54
+
55
+ You may have "fair use" rights for the software under the law. These terms do not limit them.
56
+
57
+ ## No Other Rights
58
+
59
+ These terms do not allow you to sublicense or transfer any of your licenses to anyone else, or prevent the licensor from granting licenses to anyone else. These terms do not imply any other licenses.
60
+
61
+ ## Patent Defense
62
+
63
+ If you make any written claim that the software infringes or contributes to infringement of any patent, your patent license for the software granted under these terms ends immediately. If your company makes such a claim, your patent license ends immediately for work on behalf of your company.
64
+
65
+ ## Violations
66
+
67
+ The first time you are notified in writing that you have violated any of these terms, or done anything with the software not covered by your licenses, your licenses can nonetheless continue if you come into full compliance with these terms, and take practical steps to correct past violations, within 32 days of receiving notice. Otherwise, all your licenses end immediately.
68
+
69
+ ## No Liability
70
+
71
+ ***As far as the law allows, the software comes as is, without any warranty or condition, and the licensor will not be liable to you for any damages arising out of these terms or the use or nature of the software, under any kind of legal claim.***
72
+
73
+ ## Definitions
74
+
75
+ The **licensor** is the individual or entity offering these terms, and the **software** is the software the licensor makes available under these terms.
76
+
77
+ A **product** can be a good or service, or a combination of them.
78
+
79
+ **You** refers to the individual or entity agreeing to these terms.
80
+
81
+ **Your company** is any legal entity, sole proprietorship, or other kind of organization that you work for, plus all its affiliates.
82
+
83
+ **Affiliates** means the other organizations than an organization has control over, is under the control of, or is under common control with.
84
+
85
+ **Control** means ownership of substantially all the assets of an entity, or the power to direct its management and policies by vote, contract, or otherwise. Control can be direct or indirect.
86
+
87
+ **Your licenses** are all the licenses granted to you for the software under these terms.
88
+
89
+ **Use** means anything you do with the software requiring one of your licenses.
@@ -0,0 +1,8 @@
1
+ BoxRouter Python SDK
2
+ Copyright 2026 BoxRouter, Inc.
3
+
4
+ Licensed under PolyForm Shield License 1.0.0. See LICENSE or
5
+ https://polyformproject.org/licenses/shield/1.0.0.
6
+
7
+ Required Notice: Copyright 2026 BoxRouter, Inc.
8
+ Licensor Line of Business: BoxRouter sandbox provisioning, routing, and management products and services.
@@ -0,0 +1,53 @@
1
+ Metadata-Version: 2.4
2
+ Name: boxrouter
3
+ Version: 0.0.1a2
4
+ Summary: Python client for creating and managing BoxRouter cloud sandboxes
5
+ License-Expression: LicenseRef-PolyForm-Shield-1.0.0
6
+ License-File: LICENSE
7
+ License-File: NOTICE
8
+ Classifier: Development Status :: 3 - Alpha
9
+ Classifier: Programming Language :: Python :: 3
10
+ Requires-Dist: httpx>=0.27,<1
11
+ Requires-Python: >=3.11
12
+ Project-URL: Homepage, https://boxrouter.ai
13
+ Description-Content-Type: text/markdown
14
+
15
+ # BoxRouter Python SDK — alpha
16
+
17
+ BoxRouter is a Python client for the BoxRouter API. It creates temporary cloud
18
+ sandboxes, runs commands in them, reads their status, and requests their deletion.
19
+ A sandbox request can name eligible cloud providers; BoxRouter evaluates the
20
+ request and routes it to a provider that can satisfy it.
21
+
22
+ Requires Python 3.11 or later and a BoxRouter API key.
23
+
24
+ ```sh
25
+ python -m pip install --pre boxrouter
26
+ ```
27
+
28
+ Set `BOXROUTER_API_KEY` in your environment. The client uses
29
+ `https://boxrouter.ai/api/v1` by default; set `BOXROUTER_BASE_URL` to use another
30
+ deployment.
31
+
32
+ ```python
33
+ from boxrouter import BoxRouter
34
+
35
+ with BoxRouter() as client:
36
+ with client.sandboxes.create(
37
+ providers=["e2b", "modal"], lifetime_seconds=600
38
+ ) as sandbox:
39
+ result = sandbox.exec("python --version")
40
+ print(result.stdout, end="")
41
+ print(sandbox.get()["state"])
42
+ ```
43
+
44
+ The `providers` argument is an allowlist: BoxRouter routes only among the named
45
+ providers that meet the sandbox requirements. The client does not retry a
46
+ mutation automatically. If a request outcome is uncertain, `BoxRouterError`
47
+ exposes its `idempotency_key` so the same operation can be reconciled safely.
48
+
49
+ This alpha includes sandbox creation, command execution, status reads, and
50
+ sandbox deletion. Its API may change before the full SDK release.
51
+
52
+ Licensed under PolyForm Shield 1.0.0; see [LICENSE](LICENSE). Contact:
53
+ maintainer@boxrouter.ai.
@@ -0,0 +1,39 @@
1
+ # BoxRouter Python SDK — alpha
2
+
3
+ BoxRouter is a Python client for the BoxRouter API. It creates temporary cloud
4
+ sandboxes, runs commands in them, reads their status, and requests their deletion.
5
+ A sandbox request can name eligible cloud providers; BoxRouter evaluates the
6
+ request and routes it to a provider that can satisfy it.
7
+
8
+ Requires Python 3.11 or later and a BoxRouter API key.
9
+
10
+ ```sh
11
+ python -m pip install --pre boxrouter
12
+ ```
13
+
14
+ Set `BOXROUTER_API_KEY` in your environment. The client uses
15
+ `https://boxrouter.ai/api/v1` by default; set `BOXROUTER_BASE_URL` to use another
16
+ deployment.
17
+
18
+ ```python
19
+ from boxrouter import BoxRouter
20
+
21
+ with BoxRouter() as client:
22
+ with client.sandboxes.create(
23
+ providers=["e2b", "modal"], lifetime_seconds=600
24
+ ) as sandbox:
25
+ result = sandbox.exec("python --version")
26
+ print(result.stdout, end="")
27
+ print(sandbox.get()["state"])
28
+ ```
29
+
30
+ The `providers` argument is an allowlist: BoxRouter routes only among the named
31
+ providers that meet the sandbox requirements. The client does not retry a
32
+ mutation automatically. If a request outcome is uncertain, `BoxRouterError`
33
+ exposes its `idempotency_key` so the same operation can be reconciled safely.
34
+
35
+ This alpha includes sandbox creation, command execution, status reads, and
36
+ sandbox deletion. Its API may change before the full SDK release.
37
+
38
+ Licensed under PolyForm Shield 1.0.0; see [LICENSE](LICENSE). Contact:
39
+ maintainer@boxrouter.ai.
@@ -0,0 +1,27 @@
1
+ [build-system]
2
+ requires = ["uv_build==0.12.12"]
3
+ build-backend = "uv_build"
4
+
5
+ [project]
6
+ name = "boxrouter"
7
+ version = "0.0.1a2"
8
+ description = "Python client for creating and managing BoxRouter cloud sandboxes"
9
+ readme = "README.md"
10
+ requires-python = ">=3.11"
11
+ classifiers = [
12
+ "Development Status :: 3 - Alpha",
13
+ "Programming Language :: Python :: 3",
14
+ ]
15
+ dependencies = ["httpx>=0.27,<1"]
16
+ license = "LicenseRef-PolyForm-Shield-1.0.0"
17
+ license-files = [
18
+ "LICENSE",
19
+ "NOTICE",
20
+ ]
21
+
22
+ [project.urls]
23
+ Homepage = "https://boxrouter.ai"
24
+
25
+ [tool.uv.build-backend]
26
+ module-root = "src"
27
+ module-name = "boxrouter"
@@ -0,0 +1,27 @@
1
+ [build-system]
2
+ requires = ["uv_build==0.12.12"]
3
+ build-backend = "uv_build"
4
+
5
+ [project]
6
+ name = "boxrouter"
7
+ version = "0.0.1a2"
8
+ description = "Python client for creating and managing BoxRouter cloud sandboxes"
9
+ readme = "README.md"
10
+ requires-python = ">=3.11"
11
+ classifiers = [
12
+ "Development Status :: 3 - Alpha",
13
+ "Programming Language :: Python :: 3",
14
+ ]
15
+ dependencies = ["httpx>=0.27,<1"]
16
+ license = "LicenseRef-PolyForm-Shield-1.0.0"
17
+ license-files = [
18
+ "LICENSE",
19
+ "NOTICE",
20
+ ]
21
+
22
+ [project.urls]
23
+ Homepage = "https://boxrouter.ai"
24
+
25
+ [tool.uv.build-backend]
26
+ module-root = "src"
27
+ module-name = "boxrouter"
@@ -0,0 +1,5 @@
1
+ """BoxRouter Python API client."""
2
+
3
+ from .client import BoxRouter, BoxRouterError
4
+
5
+ __all__ = ["BoxRouter", "BoxRouterError"]
@@ -0,0 +1,212 @@
1
+ """Minimal Python client for BoxRouter sandbox API operations."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import os
6
+ from collections.abc import Mapping
7
+ from dataclasses import dataclass
8
+ from typing import Any
9
+ from urllib.parse import quote
10
+ from uuid import uuid4
11
+
12
+ import httpx
13
+
14
+
15
+ class BoxRouterError(RuntimeError):
16
+ """An API or transport error from a BoxRouter request."""
17
+
18
+ def __init__(
19
+ self,
20
+ message: str,
21
+ *,
22
+ status_code: int | None = None,
23
+ response: Any = None,
24
+ idempotency_key: str | None = None,
25
+ ) -> None:
26
+ super().__init__(message)
27
+ self.status_code = status_code
28
+ self.response = response
29
+ self.idempotency_key = idempotency_key
30
+
31
+
32
+ class BoxRouter:
33
+ """Call BoxRouter to provision, use, inspect and delete cloud sandboxes."""
34
+
35
+ def __init__(
36
+ self,
37
+ api_key: str | None = None,
38
+ *,
39
+ base_url: str | None = None,
40
+ timeout: float = 60.0,
41
+ transport: httpx.BaseTransport | None = None,
42
+ ) -> None:
43
+ key = api_key or os.getenv("BOXROUTER_API_KEY")
44
+ if not key:
45
+ raise ValueError("Pass api_key or set BOXROUTER_API_KEY")
46
+ endpoint = (
47
+ base_url or os.getenv("BOXROUTER_BASE_URL") or "https://boxrouter.ai/api/v1"
48
+ ).rstrip("/")
49
+ self._client = httpx.Client(
50
+ base_url=f"{endpoint}/",
51
+ headers={"Authorization": f"Bearer {key}"},
52
+ timeout=timeout,
53
+ transport=transport,
54
+ )
55
+ self.sandboxes = _Sandboxes(self)
56
+
57
+ def create_sandbox(
58
+ self,
59
+ request: Mapping[str, Any] | None = None,
60
+ *,
61
+ idempotency_key: str | None = None,
62
+ ) -> dict[str, Any]:
63
+ """Create a sandbox; `providers` in request limits eligible cloud providers."""
64
+ result = self._request(
65
+ "POST", "sandboxes", body=dict(request or {}), idempotency_key=idempotency_key
66
+ )
67
+ return self._object(result)
68
+
69
+ def get_sandbox(self, sandbox_id: str) -> dict[str, Any]:
70
+ """Read the current BoxRouter record for a sandbox."""
71
+ result = self._request("GET", f"sandboxes/{quote(sandbox_id, safe='')}")
72
+ return self._object(result)
73
+
74
+ def run_command(
75
+ self,
76
+ sandbox_id: str,
77
+ command: str,
78
+ *,
79
+ timeout_seconds: int = 60,
80
+ idempotency_key: str | None = None,
81
+ ) -> dict[str, Any]:
82
+ """Execute one command in a sandbox and return its output and exit code."""
83
+ result = self._request(
84
+ "POST",
85
+ f"sandboxes/{quote(sandbox_id, safe='')}/commands",
86
+ body={"command": command, "timeout_seconds": timeout_seconds},
87
+ idempotency_key=idempotency_key,
88
+ )
89
+ return self._object(result)
90
+
91
+ def delete_sandbox(self, sandbox_id: str) -> None:
92
+ """Request destruction of a sandbox."""
93
+ self._request("DELETE", f"sandboxes/{quote(sandbox_id, safe='')}")
94
+
95
+ def close(self) -> None:
96
+ self._client.close()
97
+
98
+ def __enter__(self) -> BoxRouter:
99
+ return self
100
+
101
+ def __exit__(self, *_: object) -> None:
102
+ self.close()
103
+
104
+ @staticmethod
105
+ def _object(value: Any) -> dict[str, Any]:
106
+ if not isinstance(value, dict):
107
+ raise BoxRouterError("BoxRouter returned an unexpected response")
108
+ return value
109
+
110
+ def _request(
111
+ self,
112
+ method: str,
113
+ path: str,
114
+ *,
115
+ body: Mapping[str, Any] | None = None,
116
+ idempotency_key: str | None = None,
117
+ ) -> Any:
118
+ key = idempotency_key or uuid4().hex if method in {"POST", "PUT", "PATCH"} else None
119
+ headers = {"Idempotency-Key": key} if key else None
120
+ try:
121
+ response = self._client.request(
122
+ method, path, json=dict(body) if body is not None else None, headers=headers
123
+ )
124
+ except httpx.HTTPError as error:
125
+ raise BoxRouterError(
126
+ "BoxRouter request outcome is unknown; reconcile before retrying",
127
+ idempotency_key=key,
128
+ ) from error
129
+ if response.is_error:
130
+ try:
131
+ detail: Any = response.json()
132
+ except ValueError:
133
+ detail = response.text
134
+ raise BoxRouterError(
135
+ f"BoxRouter request failed with HTTP {response.status_code}",
136
+ status_code=response.status_code,
137
+ response=detail,
138
+ idempotency_key=key,
139
+ )
140
+ if response.status_code == 204 or not response.content:
141
+ return None
142
+ return response.json()
143
+
144
+
145
+ @dataclass(frozen=True)
146
+ class CommandResult:
147
+ """Text output and exit status from one sandbox command."""
148
+
149
+ stdout: str
150
+ stderr: str
151
+ exit_code: int
152
+
153
+
154
+ class _Sandboxes:
155
+ def __init__(self, client: BoxRouter) -> None:
156
+ self._client = client
157
+
158
+ def create(
159
+ self,
160
+ *,
161
+ providers: list[str] | None = None,
162
+ lifetime_seconds: int | None = None,
163
+ **request: Any,
164
+ ) -> _SandboxHandle:
165
+ body = dict(request)
166
+ if providers is not None:
167
+ body["providers"] = providers
168
+ if lifetime_seconds is not None:
169
+ body["lifetime_seconds"] = lifetime_seconds
170
+ return _SandboxHandle(self._client, self._client.create_sandbox(body))
171
+
172
+ def get(self, sandbox_id: str) -> _SandboxHandle:
173
+ return _SandboxHandle(self._client, self._client.get_sandbox(sandbox_id))
174
+
175
+ def delete(self, sandbox_id: str) -> None:
176
+ self._client.delete_sandbox(sandbox_id)
177
+
178
+
179
+ class _SandboxHandle:
180
+ def __init__(self, client: BoxRouter, metadata: Mapping[str, Any]) -> None:
181
+ sandbox_id = metadata.get("id")
182
+ if not isinstance(sandbox_id, str) or not sandbox_id:
183
+ raise BoxRouterError("BoxRouter response did not include a sandbox ID")
184
+ self._client = client
185
+ self.id = sandbox_id
186
+
187
+ def exec(self, command: str, *, timeout_seconds: int = 60) -> CommandResult:
188
+ result = self._client.run_command(self.id, command, timeout_seconds=timeout_seconds)
189
+ stdout, stderr, exit_code = (
190
+ result.get("stdout", ""),
191
+ result.get("stderr", ""),
192
+ result.get("exit_code"),
193
+ )
194
+ if (
195
+ not isinstance(stdout, str)
196
+ or not isinstance(stderr, str)
197
+ or not isinstance(exit_code, int)
198
+ ):
199
+ raise BoxRouterError("BoxRouter returned an unexpected command result")
200
+ return CommandResult(stdout, stderr, exit_code)
201
+
202
+ def get(self) -> dict[str, Any]:
203
+ return self._client.get_sandbox(self.id)
204
+
205
+ def destroy(self) -> None:
206
+ self._client.delete_sandbox(self.id)
207
+
208
+ def __enter__(self) -> _SandboxHandle:
209
+ return self
210
+
211
+ def __exit__(self, *_: object) -> None:
212
+ self.destroy()
File without changes