bonya 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.
bonya-1.0.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Bonya
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.
bonya-1.0.0/PKG-INFO ADDED
@@ -0,0 +1,162 @@
1
+ Metadata-Version: 2.4
2
+ Name: bonya
3
+ Version: 1.0.0
4
+ Summary: Synchronous Python SDK for Bonya sandboxes
5
+ License-Expression: MIT
6
+ Project-URL: Repository, https://github.com/bonyai/bonya-python
7
+ Keywords: bonya,sandbox,sdk
8
+ Classifier: Development Status :: 5 - Production/Stable
9
+ Classifier: Intended Audience :: Developers
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.10
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Typing :: Typed
15
+ Requires-Python: >=3.10
16
+ Description-Content-Type: text/markdown
17
+ License-File: LICENSE
18
+ Requires-Dist: httpx<1,>=0.27
19
+ Requires-Dist: websockets>=13
20
+ Provides-Extra: dev
21
+ Requires-Dist: build>=1.0; extra == "dev"
22
+ Requires-Dist: mypy>=1.8; extra == "dev"
23
+ Requires-Dist: pytest>=8; extra == "dev"
24
+ Requires-Dist: twine>=6.2; extra == "dev"
25
+ Dynamic: license-file
26
+
27
+ # Bonya Python SDK
28
+
29
+ Run code in a fast, isolated sandbox — from Python.
30
+
31
+ ```bash
32
+ python -m pip install bonya
33
+ ```
34
+
35
+ ```python
36
+ from bonya import Bonya
37
+
38
+ with Bonya() as client: # reads BONYA_API_KEY
39
+ with client.create_sandbox() as sandbox: # deleted on the way out
40
+ result = sandbox.exec(["echo", "hello"], check=True)
41
+ print(result.stdout) # hello
42
+ ```
43
+
44
+ That is a real VM: it boots in about a second, runs anything Linux runs, and is
45
+ gone when the `with` block ends.
46
+
47
+ The SDK is synchronous. It talks to the Bonya REST API over HTTPS
48
+ (`httpx`), and to the edge over a WebSocket (`websockets`) for streaming exec
49
+ and terminal sessions. Python 3.10 or newer; fully typed (`py.typed`).
50
+
51
+ ## Configuration
52
+
53
+ Every setting has an environment-variable fallback:
54
+
55
+ | Argument | Environment variable | Default |
56
+ |---|---|---|
57
+ | `api_key` | `BONYA_API_KEY` | *required* |
58
+ | `endpoint` | `BONYA_ENDPOINT` | `https://api.bonya.ai` |
59
+ | `edge_endpoint` | `BONYA_EDGE_ENDPOINT` | the API endpoint |
60
+ | `organization_id` | `BONYA_ORGANIZATION_ID` | your personal organization |
61
+ | `ca_bundle` | `BONYA_CA_BUNDLE` | system trust store |
62
+ | `timeout` | — | `30` (seconds) |
63
+ | `max_retries` | — | `2` |
64
+ | `filesystem_read_limit` | — | 64 MiB |
65
+
66
+ An empty `organization_id` is an error rather than a silent fallback to your
67
+ personal organization.
68
+
69
+ ## What you can do
70
+
71
+ | I want to… | Call |
72
+ |---|---|
73
+ | Start a sandbox | `client.create_sandbox(template=, image=, snapshot=, gpu=, network=, env=, secret_sets=)` |
74
+ | Reconnect to one | `client.get_sandbox(id)` / `.get_sandbox_by_name(name)` |
75
+ | Find my sandboxes | `client.list_sandboxes(states=, name=)` |
76
+ | Run a command | `sandbox.exec(cmd)` |
77
+ | Stream output live | `sandbox.exec_stream(cmd)` |
78
+ | Keep a process running after I disconnect | `sandbox.create_session(name, cmd)` / `.attach_session(name)` |
79
+ | Move files in and out | `sandbox.read_file` / `.write_file` / `.upload_file` / `.download_file` / `.list_files` / `.stat_file` / `.mkdir_file` / `.remove_file` / `.move_file` |
80
+ | Expose a port to the web | `sandbox.create_preview(port)` |
81
+ | Capture disk state | `sandbox.snapshot()` / `.list_snapshots()` |
82
+ | Clone a running sandbox | `sandbox.fork(count)` |
83
+ | Pause or keep awake | `sandbox.pause("warm" \| "cold")` / `.keepalive(seconds)` / `.resume()` |
84
+ | Restrict egress | `sandbox.update_network(NetworkPolicy(mode="allowlist", allow=[NetworkRule(domain="pypi.org")]))` |
85
+ | Run a managed or scheduled job | `client.run_job(spec)` / `client.create_job_schedule(schedule, job)` |
86
+ | See GPU capacity | `client.list_gpu_options()` |
87
+ | Save a launch configuration | `client.create_template(name, config=TemplateConfig(...))` / `.list_templates()` / `.update_template()` / `.delete_template()` |
88
+ | Pull private images | `client.create_registry_connection(...)` / `.validate_registry_connection(id, image)` |
89
+ | Keep credentials out of code | `client.create_secret(name, value)` / `.create_secret_set(name, values)` (values are write-only) |
90
+ | Switch organization | `client.list_organizations()` / `client.organization_id = id` |
91
+
92
+ Everything is a **flat method** on `Bonya` or `Sandbox`.
93
+
94
+ ### Streaming exec
95
+
96
+ ```python
97
+ from bonya import Exit, Stderr, Stdout
98
+
99
+ with sandbox.exec_stream(["bash", "-lc", "echo out; echo err >&2"]) as session:
100
+ for event in session:
101
+ if isinstance(event, Stdout):
102
+ print("out:", event.data.decode(), end="")
103
+ elif isinstance(event, Stderr):
104
+ print("err:", event.data.decode(), end="")
105
+ elif isinstance(event, Exit):
106
+ print("exit:", event.exit_code)
107
+ ```
108
+
109
+ ### Persistent sessions
110
+
111
+ ```python
112
+ sandbox.create_session("server", ["bash"])
113
+ with sandbox.attach_session("server") as stream:
114
+ stream.write("npm run dev\n")
115
+ for event in stream:
116
+ ... # Stdout, Exit, SessionEnded, SessionOutputDropped
117
+ # leaving the block detaches; the process keeps running
118
+ ```
119
+
120
+ ### Jobs
121
+
122
+ ```python
123
+ from bonya import JobSandboxSpec, JobSpec
124
+
125
+ run = client.run_job(JobSpec(new_sandbox=JobSandboxSpec(), cmd=["./run-tests.sh"]))
126
+ print(run.status, run.result.exit_code)
127
+ ```
128
+
129
+ ### Snapshots and forks
130
+
131
+ ```python
132
+ snapshot = sandbox.snapshot(name="baseline")
133
+ restored = client.create_sandbox(snapshot=snapshot.id)
134
+ forks = sandbox.fork(2).sandboxes
135
+ ```
136
+
137
+ ## Errors
138
+
139
+ Every error extends `BonyaError` (with `sandbox_id`, `idempotency_key`, `code`).
140
+ Catch the class you care about: `AuthenticationError`, `SandboxNotFoundError`,
141
+ `SandboxCreationTimeoutError` (carries the `idempotency_key` so create can be
142
+ retried), `ExecFailedError`, `TimeoutError`, `NoCapacityError`,
143
+ `RateLimitedError`, `OutcomeUnknownError`, `RemoteFileNotFoundError`, and so on.
144
+ API keys and capability tokens are redacted from error messages.
145
+
146
+ Create, exec, snapshot and other mutations accept an `idempotency_key`; the SDK
147
+ generates one and reuses it across its own retries, so a retried call joins the
148
+ original attempt instead of repeating it.
149
+
150
+ ## Examples
151
+
152
+ Runnable programs live in [`examples/`](examples): `quickstart.py`,
153
+ `exec_streaming.py`, `files.py`, `sessions.py`, `previews.py`, `snapshots.py`.
154
+
155
+ ## Development
156
+
157
+ ```bash
158
+ python -m pip install -e '.[dev]'
159
+ make check # mypy + pytest
160
+ ```
161
+
162
+ MIT licensed.
bonya-1.0.0/README.md ADDED
@@ -0,0 +1,136 @@
1
+ # Bonya Python SDK
2
+
3
+ Run code in a fast, isolated sandbox — from Python.
4
+
5
+ ```bash
6
+ python -m pip install bonya
7
+ ```
8
+
9
+ ```python
10
+ from bonya import Bonya
11
+
12
+ with Bonya() as client: # reads BONYA_API_KEY
13
+ with client.create_sandbox() as sandbox: # deleted on the way out
14
+ result = sandbox.exec(["echo", "hello"], check=True)
15
+ print(result.stdout) # hello
16
+ ```
17
+
18
+ That is a real VM: it boots in about a second, runs anything Linux runs, and is
19
+ gone when the `with` block ends.
20
+
21
+ The SDK is synchronous. It talks to the Bonya REST API over HTTPS
22
+ (`httpx`), and to the edge over a WebSocket (`websockets`) for streaming exec
23
+ and terminal sessions. Python 3.10 or newer; fully typed (`py.typed`).
24
+
25
+ ## Configuration
26
+
27
+ Every setting has an environment-variable fallback:
28
+
29
+ | Argument | Environment variable | Default |
30
+ |---|---|---|
31
+ | `api_key` | `BONYA_API_KEY` | *required* |
32
+ | `endpoint` | `BONYA_ENDPOINT` | `https://api.bonya.ai` |
33
+ | `edge_endpoint` | `BONYA_EDGE_ENDPOINT` | the API endpoint |
34
+ | `organization_id` | `BONYA_ORGANIZATION_ID` | your personal organization |
35
+ | `ca_bundle` | `BONYA_CA_BUNDLE` | system trust store |
36
+ | `timeout` | — | `30` (seconds) |
37
+ | `max_retries` | — | `2` |
38
+ | `filesystem_read_limit` | — | 64 MiB |
39
+
40
+ An empty `organization_id` is an error rather than a silent fallback to your
41
+ personal organization.
42
+
43
+ ## What you can do
44
+
45
+ | I want to… | Call |
46
+ |---|---|
47
+ | Start a sandbox | `client.create_sandbox(template=, image=, snapshot=, gpu=, network=, env=, secret_sets=)` |
48
+ | Reconnect to one | `client.get_sandbox(id)` / `.get_sandbox_by_name(name)` |
49
+ | Find my sandboxes | `client.list_sandboxes(states=, name=)` |
50
+ | Run a command | `sandbox.exec(cmd)` |
51
+ | Stream output live | `sandbox.exec_stream(cmd)` |
52
+ | Keep a process running after I disconnect | `sandbox.create_session(name, cmd)` / `.attach_session(name)` |
53
+ | Move files in and out | `sandbox.read_file` / `.write_file` / `.upload_file` / `.download_file` / `.list_files` / `.stat_file` / `.mkdir_file` / `.remove_file` / `.move_file` |
54
+ | Expose a port to the web | `sandbox.create_preview(port)` |
55
+ | Capture disk state | `sandbox.snapshot()` / `.list_snapshots()` |
56
+ | Clone a running sandbox | `sandbox.fork(count)` |
57
+ | Pause or keep awake | `sandbox.pause("warm" \| "cold")` / `.keepalive(seconds)` / `.resume()` |
58
+ | Restrict egress | `sandbox.update_network(NetworkPolicy(mode="allowlist", allow=[NetworkRule(domain="pypi.org")]))` |
59
+ | Run a managed or scheduled job | `client.run_job(spec)` / `client.create_job_schedule(schedule, job)` |
60
+ | See GPU capacity | `client.list_gpu_options()` |
61
+ | Save a launch configuration | `client.create_template(name, config=TemplateConfig(...))` / `.list_templates()` / `.update_template()` / `.delete_template()` |
62
+ | Pull private images | `client.create_registry_connection(...)` / `.validate_registry_connection(id, image)` |
63
+ | Keep credentials out of code | `client.create_secret(name, value)` / `.create_secret_set(name, values)` (values are write-only) |
64
+ | Switch organization | `client.list_organizations()` / `client.organization_id = id` |
65
+
66
+ Everything is a **flat method** on `Bonya` or `Sandbox`.
67
+
68
+ ### Streaming exec
69
+
70
+ ```python
71
+ from bonya import Exit, Stderr, Stdout
72
+
73
+ with sandbox.exec_stream(["bash", "-lc", "echo out; echo err >&2"]) as session:
74
+ for event in session:
75
+ if isinstance(event, Stdout):
76
+ print("out:", event.data.decode(), end="")
77
+ elif isinstance(event, Stderr):
78
+ print("err:", event.data.decode(), end="")
79
+ elif isinstance(event, Exit):
80
+ print("exit:", event.exit_code)
81
+ ```
82
+
83
+ ### Persistent sessions
84
+
85
+ ```python
86
+ sandbox.create_session("server", ["bash"])
87
+ with sandbox.attach_session("server") as stream:
88
+ stream.write("npm run dev\n")
89
+ for event in stream:
90
+ ... # Stdout, Exit, SessionEnded, SessionOutputDropped
91
+ # leaving the block detaches; the process keeps running
92
+ ```
93
+
94
+ ### Jobs
95
+
96
+ ```python
97
+ from bonya import JobSandboxSpec, JobSpec
98
+
99
+ run = client.run_job(JobSpec(new_sandbox=JobSandboxSpec(), cmd=["./run-tests.sh"]))
100
+ print(run.status, run.result.exit_code)
101
+ ```
102
+
103
+ ### Snapshots and forks
104
+
105
+ ```python
106
+ snapshot = sandbox.snapshot(name="baseline")
107
+ restored = client.create_sandbox(snapshot=snapshot.id)
108
+ forks = sandbox.fork(2).sandboxes
109
+ ```
110
+
111
+ ## Errors
112
+
113
+ Every error extends `BonyaError` (with `sandbox_id`, `idempotency_key`, `code`).
114
+ Catch the class you care about: `AuthenticationError`, `SandboxNotFoundError`,
115
+ `SandboxCreationTimeoutError` (carries the `idempotency_key` so create can be
116
+ retried), `ExecFailedError`, `TimeoutError`, `NoCapacityError`,
117
+ `RateLimitedError`, `OutcomeUnknownError`, `RemoteFileNotFoundError`, and so on.
118
+ API keys and capability tokens are redacted from error messages.
119
+
120
+ Create, exec, snapshot and other mutations accept an `idempotency_key`; the SDK
121
+ generates one and reuses it across its own retries, so a retried call joins the
122
+ original attempt instead of repeating it.
123
+
124
+ ## Examples
125
+
126
+ Runnable programs live in [`examples/`](examples): `quickstart.py`,
127
+ `exec_streaming.py`, `files.py`, `sessions.py`, `previews.py`, `snapshots.py`.
128
+
129
+ ## Development
130
+
131
+ ```bash
132
+ python -m pip install -e '.[dev]'
133
+ make check # mypy + pytest
134
+ ```
135
+
136
+ MIT licensed.
@@ -0,0 +1,52 @@
1
+ [build-system]
2
+ requires = ["setuptools>=69", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "bonya"
7
+ version = "1.0.0"
8
+ description = "Synchronous Python SDK for Bonya sandboxes"
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ license = "MIT"
12
+ license-files = ["LICENSE"]
13
+ keywords = ["bonya", "sandbox", "sdk"]
14
+ dependencies = [
15
+ "httpx>=0.27,<1",
16
+ "websockets>=13",
17
+ ]
18
+ classifiers = [
19
+ "Development Status :: 5 - Production/Stable",
20
+ "Intended Audience :: Developers",
21
+ "Programming Language :: Python :: 3",
22
+ "Programming Language :: Python :: 3.10",
23
+ "Programming Language :: Python :: 3.11",
24
+ "Programming Language :: Python :: 3.12",
25
+ "Typing :: Typed",
26
+ ]
27
+
28
+ [project.urls]
29
+ Repository = "https://github.com/bonyai/bonya-python"
30
+
31
+ [project.optional-dependencies]
32
+ dev = [
33
+ "build>=1.0",
34
+ "mypy>=1.8",
35
+ "pytest>=8",
36
+ "twine>=6.2",
37
+ ]
38
+
39
+ [tool.setuptools.packages.find]
40
+ where = ["src"]
41
+ include = ["bonya*"]
42
+
43
+ [tool.setuptools.package-data]
44
+ bonya = ["py.typed"]
45
+
46
+ [tool.pytest.ini_options]
47
+ testpaths = ["tests"]
48
+
49
+ [tool.mypy]
50
+ python_version = "3.10"
51
+ strict = true
52
+ packages = ["bonya"]
bonya-1.0.0/setup.cfg ADDED
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,101 @@
1
+ """Synchronous Python SDK for Bonya sandboxes."""
2
+
3
+ from ._client import Bonya, Organization, SandboxSummary
4
+ from ._errors import (
5
+ AuthenticationError,
6
+ BonyaError,
7
+ CapabilityRejectedError,
8
+ ConflictError,
9
+ ConnectionError,
10
+ CrossFilesystemMoveError,
11
+ ExecFailedError,
12
+ FilesystemError,
13
+ FilesystemLimitError,
14
+ InvalidRequestError,
15
+ JobRunNotFoundError,
16
+ JobScheduleNotFoundError,
17
+ LimitReachedError,
18
+ NoCapacityError,
19
+ OutcomeUnknownError,
20
+ PayloadTooLargeError,
21
+ PermissionDeniedError,
22
+ RateLimitedError,
23
+ RemoteFileExistsError,
24
+ RemoteFileNotFoundError,
25
+ SandboxBusyError,
26
+ SandboxCreationFailedError,
27
+ SandboxCreationTimeoutError,
28
+ SandboxDeletedError,
29
+ SandboxFailedError,
30
+ SandboxNotFoundError,
31
+ SandboxSuspendedError,
32
+ ServiceError,
33
+ SessionExists,
34
+ SessionExistsError,
35
+ SessionNotFoundError,
36
+ SnapshotInUseError,
37
+ SnapshotNotFoundError,
38
+ TimeoutError,
39
+ )
40
+ from ._files import FileInfo, FileKind
41
+ from ._jobs import (
42
+ Disposition,
43
+ JobResult,
44
+ JobRun,
45
+ JobRunAction,
46
+ JobRunDetail,
47
+ JobRunStatus,
48
+ JobRunTimelineEntry,
49
+ JobRunTimelineStatus,
50
+ JobSandboxSpec,
51
+ JobSchedule,
52
+ JobScriptSpec,
53
+ JobSpec,
54
+ JobStart,
55
+ ScheduleAction,
56
+ ScheduleOverlap,
57
+ ScheduleSpec,
58
+ )
59
+ from ._library import RegistryConnection, Secret, SecretSet, Template, TemplateConfig
60
+ from ._previews import Preview, PreviewAuth, PreviewGrant
61
+ from ._sandbox import Capability, DeleteResult, ExecResult, ForkResult, ResumeResult, Sandbox, Snapshot
62
+ from ._session import ExecSession
63
+ from ._sessions import (
64
+ SessionEnded,
65
+ SessionEndedReason,
66
+ SessionInfo,
67
+ SessionList,
68
+ SessionOutputDropped,
69
+ SessionStatus,
70
+ SessionStream,
71
+ )
72
+ from ._types import (
73
+ LISTABLE_STATUSES,
74
+ ExecEvent,
75
+ Exit,
76
+ GpuRequest,
77
+ NetworkPolicy,
78
+ NetworkRule,
79
+ Status,
80
+ Stderr,
81
+ Stdout,
82
+ Wait,
83
+ )
84
+
85
+ __all__ = [
86
+ "AuthenticationError", "Bonya", "BonyaError", "Capability", "CapabilityRejectedError", "ConflictError",
87
+ "ConnectionError", "CrossFilesystemMoveError", "DeleteResult", "Disposition", "ExecEvent", "ExecFailedError",
88
+ "ExecResult", "ExecSession", "Exit", "FileInfo", "FileKind", "FilesystemError", "FilesystemLimitError",
89
+ "ForkResult", "GpuRequest", "InvalidRequestError", "JobResult", "JobRun", "JobRunAction", "JobRunDetail",
90
+ "JobRunNotFoundError", "JobRunStatus", "JobRunTimelineEntry", "JobRunTimelineStatus", "JobSandboxSpec",
91
+ "JobSchedule", "JobScheduleNotFoundError", "JobScriptSpec", "JobSpec", "JobStart", "LISTABLE_STATUSES",
92
+ "LimitReachedError", "NetworkPolicy", "NetworkRule", "NoCapacityError", "Organization", "OutcomeUnknownError",
93
+ "PayloadTooLargeError", "PermissionDeniedError", "Preview", "PreviewAuth", "PreviewGrant", "RateLimitedError",
94
+ "RegistryConnection", "RemoteFileExistsError", "RemoteFileNotFoundError", "ResumeResult", "Sandbox",
95
+ "SandboxBusyError", "SandboxCreationFailedError", "SandboxCreationTimeoutError", "SandboxDeletedError",
96
+ "SandboxFailedError", "SandboxNotFoundError", "SandboxSummary", "SandboxSuspendedError", "ScheduleAction",
97
+ "ScheduleOverlap", "ScheduleSpec", "Secret", "SecretSet", "ServiceError", "SessionEnded", "SessionEndedReason",
98
+ "SessionExists", "SessionExistsError", "SessionInfo", "SessionList", "SessionNotFoundError",
99
+ "SessionOutputDropped", "SessionStatus", "SessionStream", "Snapshot", "SnapshotInUseError",
100
+ "SnapshotNotFoundError", "Status", "Stderr", "Stdout", "Template", "TemplateConfig", "TimeoutError", "Wait",
101
+ ]