@genspark/sb-box 0.0.0-stage → 0.1.0

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.
package/CHANGELOG.md ADDED
@@ -0,0 +1,14 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0 — 2026-11-04
4
+
5
+ Initial release.
6
+
7
+ - `SbBox` client: regions, limits, usage, templates (build / waitReady / list / shared / get /
8
+ delete / grants) and sandboxes (create / list / shared / get / kill / freeze / resume / rollback /
9
+ clone / setTimeout / reset / metrics / grants).
10
+ - `Sandbox` handle: `exec`, `execStream` (SSE), `runCode`, background `commands`, `files`
11
+ (bytes/text), `pty` (SSE and WebSocket), `portUrl`.
12
+ - Typed error classes mapped from HTTP status and error codes; API keys redacted from messages.
13
+ - Built-in retries for reads and idempotent lifecycle calls; `Retry-After` honoured on clone / reset.
14
+ - ESM + CommonJS builds, bundled type declarations, zero runtime dependencies.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Genspark
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.
package/README.md CHANGED
@@ -1,3 +1,103 @@
1
- # Temporary Holding Version
1
+ # @genspark/sb-box
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ TypeScript / JavaScript SDK for [Genspark SB-Box](https://www.genspark.ai/sb-box/docs) — fast
4
+ sandboxes you can create, run commands in, freeze and resume, from Node 18+ (or any runtime with
5
+ `fetch`).
6
+
7
+ ```bash
8
+ npm install @genspark/sb-box
9
+ ```
10
+
11
+ ## Quickstart
12
+
13
+ ```ts
14
+ import { SbBox } from '@genspark/sb-box'
15
+
16
+ const sbbox = new SbBox({ apiKey: process.env.SBBOX_API_KEY })
17
+
18
+ const sandbox = await sbbox.sandboxes.create({ timeout: 600 }) // public "base" template
19
+ const r = await sandbox.exec('python3 -c "print(6*7)"')
20
+ console.log(r.stdout, r.exitCode) // "42\n" 0
21
+
22
+ await sandbox.files.write('/home/user/hello.txt', 'hi there')
23
+ console.log(await sandbox.files.readText('/home/user/hello.txt'))
24
+
25
+ const code = await sandbox.runCode('import sys; sys.version') // stateful interpreter
26
+ console.log(code.results[0])
27
+
28
+ await sandbox.freeze() // memory + disk kept; only disk is billed while frozen
29
+ await sandbox.resume() // back in about a second, processes intact
30
+ await sandbox.kill()
31
+ ```
32
+
33
+ Reconnect to an existing sandbox with `await sbbox.sandboxes.get(id)`.
34
+
35
+ ## Configuration
36
+
37
+ | Option | Env var | Default |
38
+ |---|---|---|
39
+ | `apiKey` | `SBBOX_API_KEY` (or `GSK_API_KEY`) | — (required) |
40
+ | `baseUrl` | `SBBOX_BASE_URL` | `https://www.genspark.ai/api/sb-box/v1` |
41
+ | `timeout` | | 60 s per request |
42
+ | `retries` | | 3 retries (after the first attempt) for reads and idempotent lifecycle calls; `0` disables |
43
+
44
+ Create a key in the Genspark console. All lifetimes in this SDK are **seconds**.
45
+
46
+ ## What's in the box
47
+
48
+ - `sbbox.regions()`, `sbbox.limits()`, `sbbox.usage(days)`
49
+ - `sbbox.templates` — `build()`, `waitReady()`, `list()`, `shared()`, `get()`, `delete()`, `grant()`, `grants()`, `revoke()`
50
+ - `sbbox.sandboxes` — `create()`, `list(state)`, `shared()`, `get()`, plus id-based `kill/freeze/resume/rollback/clone/setTimeout/reset/metrics`
51
+ - `Sandbox` handle
52
+ - `exec(command, { cwd, envVars, user, timeout })` → `{ stdout, stderr, exitCode }` (non-zero exit is **not** an error)
53
+ - `execStream(command)` → `for await (const ev of …)` with `stdout` / `stderr` / `exit` / `error` events
54
+ - `runCode(code, { language, contextId, timeout, images })` → rich results (text, html, png, …)
55
+ - `commands.start()` → background process with `input()`, `connect()`, `wait()`, `kill()`
56
+ - `files.write(path, bytes | string)`, `files.read(path)`, `files.readText(path)`, `files.list(path)`
57
+ - `pty.open()` (SSE output) and `pty.connectWs()` (WebSocket; needs Node 22+ or `npm i ws`)
58
+ - `freeze({ wait })`, `resume()`, `rollback({ version })`, `clone()`, `reset()`, `setTimeout(seconds)`, `metrics()`
59
+ - `portUrl(port)` — public URL of a service listening inside the sandbox
60
+ - `grant(userId, { perm })` / `grants()` / `revoke(userId)` to share with teammates
61
+
62
+ Streaming a long command:
63
+
64
+ ```ts
65
+ for await (const ev of sandbox.execStream(['npm', 'test'], { timeout: 300 })) {
66
+ if (ev.kind === 'stdout') process.stdout.write(ev.data!)
67
+ else if (ev.kind === 'exit') console.log('exit', ev.exitCode)
68
+ }
69
+ ```
70
+
71
+ Building your own template:
72
+
73
+ ```ts
74
+ const { templateId } = await sbbox.templates.build({ name: 'py312', image: 'python:3.12', cpuCount: 2, memoryMB: 4096 })
75
+ const tpl = await sbbox.templates.waitReady(templateId) // throws TemplateBuildError on failure
76
+ const sb = await sbbox.sandboxes.create({ templateId: tpl.id })
77
+ ```
78
+
79
+ ## Errors
80
+
81
+ Every failure is an `SbBoxError` with `status`, `code`, `message`, `detail` (raw body) and
82
+ `retryAfter`. Catch the subclass you care about:
83
+
84
+ | Class | When |
85
+ |---|---|
86
+ | `AuthenticationError` | 401 — missing or invalid key |
87
+ | `PlanRequiredError` (`plan`, `upgrade`) | 403 — your plan cannot do this |
88
+ | `InsufficientCreditsError` (`balance`) | 402 |
89
+ | `LimitError` (`limit`, `current`) | 409 — concurrency / spec / build limits |
90
+ | `NotFoundError`, `RegionRetiredError` | 404 — unknown or killed sandbox, retired region |
91
+ | `CommandTimeoutError` (`killed`) | 408 — `exec` ran past its timeout |
92
+ | `MemoryExpiredError` (`recovery`) | 428 — frozen memory expired; `reset()` boots from disk |
93
+ | `DiskLostError` | 410 — use `rollback()` |
94
+ | `InterpreterUnavailableError`, `InterpreterStartFailedError` | `runCode` on an image without the interpreter |
95
+ | `ValidationError` | 400 / 422 |
96
+ | `ServerError`, `SbBoxConnectionError` | 5xx, network / timeout |
97
+ | `TemplateBuildError`, `WaitTimeoutError` | raised by the `wait*` helpers |
98
+
99
+ API keys are redacted from every error message.
100
+
101
+ ## License
102
+
103
+ MIT