@omnirun/sdk 0.3.3 → 0.4.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 +16 -0
- package/LICENSE +21 -0
- package/README.md +128 -0
- package/dist/client.d.ts +7 -1
- package/dist/client.js +117 -41
- package/dist/command-handle.d.ts +1 -0
- package/dist/command-handle.js +1 -0
- package/dist/commands.d.ts +1 -0
- package/dist/commands.js +1 -0
- package/dist/config.d.ts +2 -0
- package/dist/config.js +2 -1
- package/dist/contexts.d.ts +1 -0
- package/dist/contexts.js +2 -1
- package/dist/e2ee.d.ts +42 -0
- package/dist/e2ee.js +107 -0
- package/dist/exposures.d.ts +1 -0
- package/dist/exposures.js +1 -0
- package/dist/filesystem.d.ts +1 -0
- package/dist/filesystem.js +1 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +1 -0
- package/dist/models.d.ts +3 -17
- package/dist/production.d.ts +4 -1
- package/dist/production.js +30 -1
- package/dist/pty.d.ts +2 -0
- package/dist/pty.js +2 -0
- package/dist/sandbox.d.ts +6 -12
- package/dist/sandbox.js +60 -45
- package/dist/watch-handle.d.ts +1 -0
- package/dist/watch-handle.js +2 -1
- package/dist/webhooks.d.ts +1 -0
- package/dist/webhooks.js +1 -0
- package/package.json +43 -10
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.4.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 9d4a061: Add automatic retry on transient server errors (500/502/503) for POST and upload requests, fixing intermittent binary file write failures. Add Exposures API for managing sandbox preview URLs. Fix E2EE test compatibility with Node 18.
|
|
8
|
+
|
|
9
|
+
All notable changes to this project will be documented in this file.
|
|
10
|
+
|
|
11
|
+
## 0.3.0 - 2026-03-04
|
|
12
|
+
|
|
13
|
+
- First standalone release of `@omnirun/sdk`.
|
|
14
|
+
- Full sandbox SDK surface extracted from OmniRun monorepo.
|
|
15
|
+
- API contract fixes for metadata filters and context stream execution.
|
|
16
|
+
- Added Changesets and CI/publish workflows.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 OmniRun
|
|
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
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
# @omnirun/sdk
|
|
2
|
+
|
|
3
|
+
TypeScript SDK for OmniRun sandboxes.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @omnirun/sdk
|
|
9
|
+
pnpm add @omnirun/sdk
|
|
10
|
+
bun add @omnirun/sdk
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Configuration
|
|
14
|
+
|
|
15
|
+
The SDK resolves configuration in this order:
|
|
16
|
+
|
|
17
|
+
1. Explicit options passed to SDK methods.
|
|
18
|
+
2. Environment variables: `OMNIRUN_API_URL`, `OMNIRUN_API_KEY`.
|
|
19
|
+
3. Default API URL: `https://api.omnirun.io`.
|
|
20
|
+
|
|
21
|
+
## Quickstart
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import { Sandbox } from "@omnirun/sdk";
|
|
25
|
+
|
|
26
|
+
const sbx = await Sandbox.create("python-3.11", {
|
|
27
|
+
apiKey: process.env.OMNIRUN_API_KEY,
|
|
28
|
+
apiUrl: process.env.OMNIRUN_API_URL,
|
|
29
|
+
timeout: 300,
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const result = await sbx.commands.run("python3 -c \"print('hello')\"");
|
|
33
|
+
console.log(result.stdout);
|
|
34
|
+
|
|
35
|
+
await sbx.kill();
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Files
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
await sbx.files.write("/tmp/input.txt", "hello");
|
|
42
|
+
const content = await sbx.files.read("/tmp/input.txt");
|
|
43
|
+
const bytes = await sbx.files.read("/tmp/input.txt", "bytes");
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Signed URLs
|
|
47
|
+
|
|
48
|
+
```ts
|
|
49
|
+
const uploadUrl = await sbx.uploadUrl("/tmp/report.json");
|
|
50
|
+
const downloadUrl = await sbx.downloadUrl("/tmp/report.json");
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Use `uploadUrl` with multipart form-data when you need to move artifacts across the sandbox boundary.
|
|
54
|
+
|
|
55
|
+
## Streaming
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
const command = await sbx.commands.run("for i in 1 2 3; do echo $i; sleep 1; done", {
|
|
59
|
+
background: true,
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
for await (const event of command) {
|
|
63
|
+
if (event.type === "stdout") {
|
|
64
|
+
process.stdout.write(event.data ?? "");
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Production controls
|
|
70
|
+
|
|
71
|
+
```ts
|
|
72
|
+
await sbx.production.setNetworkPolicy({
|
|
73
|
+
allowDomains: ["api.openai.com"],
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
const metrics = await sbx.production.metrics();
|
|
77
|
+
const snapshots = await sbx.production.metricsSnapshots();
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Integration tests
|
|
81
|
+
|
|
82
|
+
Integration tests are opt-in:
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
OMNIRUN_API_URL=https://api.omnirun.io \
|
|
86
|
+
OMNIRUN_API_KEY=<key> \
|
|
87
|
+
RUN_OMNIRUN_INTEGRATION=1 \
|
|
88
|
+
npm run test:integration
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Hosted API smoke examples
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
OMNIRUN_API_URL=https://<your-api-host> \
|
|
95
|
+
OMNIRUN_API_KEY=<key> \
|
|
96
|
+
npm run examples:hosted
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Hosted example suites live in `examples/hosted/`.
|
|
100
|
+
|
|
101
|
+
## E2EE scaffold (client key bootstrap)
|
|
102
|
+
|
|
103
|
+
The SDK can generate a client keypair and send `clientPublicKey` during sandbox creation:
|
|
104
|
+
|
|
105
|
+
```ts
|
|
106
|
+
import { Sandbox } from "@omnirun/sdk";
|
|
107
|
+
|
|
108
|
+
const sbx = await Sandbox.create("python-3.11", {
|
|
109
|
+
apiUrl: process.env.OMNIRUN_API_URL,
|
|
110
|
+
apiKey: process.env.OMNIRUN_API_KEY,
|
|
111
|
+
e2ee: true,
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
console.log(sbx.e2ee?.clientPublicKey);
|
|
115
|
+
console.log(sbx.e2ee?.serverPublicKey); // available when backend returns it
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
Protocol scaffold details: `docs/E2EE-PROTOCOL-SCAFFOLD.md`.
|
|
119
|
+
|
|
120
|
+
## API Surface
|
|
121
|
+
|
|
122
|
+
- `Sandbox`
|
|
123
|
+
- `Commands` / `CommandHandle`
|
|
124
|
+
- `Filesystem`
|
|
125
|
+
- `Pty` / `PtySession`
|
|
126
|
+
- `Contexts`
|
|
127
|
+
- `Production`
|
|
128
|
+
- `Webhooks`
|
package/dist/client.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import type { ConnectionConfig } from "./config.js";
|
|
2
2
|
import type { StreamEvent } from "./models.js";
|
|
3
|
+
/** Low-level HTTP transport for OmniRun API requests. */
|
|
3
4
|
export declare class HTTPClient {
|
|
4
5
|
private config;
|
|
5
6
|
constructor(config: ConnectionConfig);
|
|
6
7
|
get baseUrl(): string;
|
|
7
|
-
private get
|
|
8
|
+
private get authHeaders();
|
|
9
|
+
private get jsonHeaders();
|
|
8
10
|
get<T = any>(path: string, params?: Record<string, string>): Promise<T>;
|
|
9
11
|
post<T = any>(path: string, body?: any): Promise<T>;
|
|
10
12
|
delete(path: string, params?: Record<string, string>): Promise<void>;
|
|
@@ -16,6 +18,10 @@ export declare class HTTPClient {
|
|
|
16
18
|
}>;
|
|
17
19
|
upload(path: string, filePath: string, content: Uint8Array, filename: string): Promise<any>;
|
|
18
20
|
streamSSE(path: string, params?: Record<string, string>): AsyncGenerator<StreamEvent>;
|
|
21
|
+
streamSSEPost(path: string, body?: unknown, signal?: AbortSignal): AsyncGenerator<StreamEvent>;
|
|
22
|
+
streamSSEWithSignal(path: string, params?: Record<string, string>, signal?: AbortSignal): AsyncGenerator<StreamEvent>;
|
|
19
23
|
private buildUrl;
|
|
20
24
|
private handle;
|
|
25
|
+
private parseSSE;
|
|
26
|
+
private errorMessage;
|
|
21
27
|
}
|
package/dist/client.js
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
import { SandboxError, StreamError } from "./errors.js";
|
|
2
|
+
/** Maximum number of retry attempts for retryable server errors. */
|
|
3
|
+
const MAX_RETRIES = 2;
|
|
4
|
+
/** HTTP status codes that are safe to retry (transient server errors). */
|
|
5
|
+
function isRetryable(status) {
|
|
6
|
+
return status === 500 || status === 502 || status === 503;
|
|
7
|
+
}
|
|
8
|
+
/** Low-level HTTP transport for OmniRun API requests. */
|
|
2
9
|
export class HTTPClient {
|
|
3
10
|
config;
|
|
4
11
|
constructor(config) {
|
|
@@ -7,36 +14,49 @@ export class HTTPClient {
|
|
|
7
14
|
get baseUrl() {
|
|
8
15
|
return this.config.apiUrl;
|
|
9
16
|
}
|
|
10
|
-
get
|
|
11
|
-
const h = {
|
|
17
|
+
get authHeaders() {
|
|
18
|
+
const h = {};
|
|
12
19
|
if (this.config.apiKey) {
|
|
13
20
|
h["X-API-Key"] = this.config.apiKey;
|
|
14
21
|
}
|
|
15
22
|
return h;
|
|
16
23
|
}
|
|
24
|
+
get jsonHeaders() {
|
|
25
|
+
return { ...this.authHeaders, "Content-Type": "application/json" };
|
|
26
|
+
}
|
|
17
27
|
async get(path, params) {
|
|
18
28
|
const url = this.buildUrl(path, params);
|
|
19
29
|
const resp = await fetch(url, {
|
|
20
30
|
method: "GET",
|
|
21
|
-
headers: this.
|
|
31
|
+
headers: this.authHeaders,
|
|
22
32
|
signal: AbortSignal.timeout(this.config.requestTimeout),
|
|
23
33
|
});
|
|
24
34
|
return this.handle(resp);
|
|
25
35
|
}
|
|
26
36
|
async post(path, body) {
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
37
|
+
const jsonBody = body != null ? JSON.stringify(body) : undefined;
|
|
38
|
+
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
|
39
|
+
const resp = await fetch(this.buildUrl(path), {
|
|
40
|
+
method: "POST",
|
|
41
|
+
headers: this.jsonHeaders,
|
|
42
|
+
body: jsonBody,
|
|
43
|
+
signal: AbortSignal.timeout(this.config.requestTimeout),
|
|
44
|
+
});
|
|
45
|
+
if (isRetryable(resp.status) && attempt < MAX_RETRIES - 1) {
|
|
46
|
+
// Drain response body before retrying
|
|
47
|
+
await resp.text();
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
return this.handle(resp);
|
|
51
|
+
}
|
|
52
|
+
// Unreachable, but TypeScript needs it
|
|
53
|
+
throw new SandboxError("max retries exceeded");
|
|
34
54
|
}
|
|
35
55
|
async delete(path, params) {
|
|
36
56
|
const url = this.buildUrl(path, params);
|
|
37
57
|
const resp = await fetch(url, {
|
|
38
58
|
method: "DELETE",
|
|
39
|
-
headers: this.
|
|
59
|
+
headers: this.authHeaders,
|
|
40
60
|
signal: AbortSignal.timeout(this.config.requestTimeout),
|
|
41
61
|
});
|
|
42
62
|
if (resp.status === 204)
|
|
@@ -76,39 +96,97 @@ export class HTTPClient {
|
|
|
76
96
|
const url = this.buildUrl(path, params);
|
|
77
97
|
const resp = await fetch(url, {
|
|
78
98
|
method: "GET",
|
|
79
|
-
headers: this.
|
|
99
|
+
headers: this.authHeaders,
|
|
80
100
|
signal: AbortSignal.timeout(this.config.requestTimeout),
|
|
81
101
|
});
|
|
82
102
|
const data = await this.handle(resp);
|
|
83
103
|
return { data, headers: resp.headers };
|
|
84
104
|
}
|
|
85
105
|
async upload(path, filePath, content, filename) {
|
|
86
|
-
const form = new FormData();
|
|
87
|
-
form.append("path", filePath);
|
|
88
|
-
form.append("file", new Blob([content]), filename);
|
|
89
106
|
const headers = {};
|
|
90
107
|
if (this.config.apiKey) {
|
|
91
108
|
headers["X-API-Key"] = this.config.apiKey;
|
|
92
109
|
}
|
|
110
|
+
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
|
111
|
+
// Rebuild FormData for each attempt since the body stream is consumed
|
|
112
|
+
const form = new FormData();
|
|
113
|
+
form.append("path", filePath);
|
|
114
|
+
form.append("file", new Blob([content]), filename);
|
|
115
|
+
const resp = await fetch(this.buildUrl(path), {
|
|
116
|
+
method: "POST",
|
|
117
|
+
headers,
|
|
118
|
+
body: form,
|
|
119
|
+
signal: AbortSignal.timeout(this.config.requestTimeout),
|
|
120
|
+
});
|
|
121
|
+
if (isRetryable(resp.status) && attempt < MAX_RETRIES - 1) {
|
|
122
|
+
await resp.text();
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
return this.handle(resp);
|
|
126
|
+
}
|
|
127
|
+
throw new SandboxError("max retries exceeded");
|
|
128
|
+
}
|
|
129
|
+
async *streamSSE(path, params) {
|
|
130
|
+
const url = this.buildUrl(path, params);
|
|
131
|
+
const resp = await fetch(url, {
|
|
132
|
+
method: "GET",
|
|
133
|
+
headers: {
|
|
134
|
+
...this.authHeaders,
|
|
135
|
+
Accept: "text/event-stream",
|
|
136
|
+
},
|
|
137
|
+
});
|
|
138
|
+
yield* this.parseSSE(resp);
|
|
139
|
+
}
|
|
140
|
+
async *streamSSEPost(path, body, signal) {
|
|
93
141
|
const resp = await fetch(this.buildUrl(path), {
|
|
94
142
|
method: "POST",
|
|
95
|
-
headers
|
|
96
|
-
|
|
97
|
-
|
|
143
|
+
headers: {
|
|
144
|
+
...this.jsonHeaders,
|
|
145
|
+
Accept: "text/event-stream",
|
|
146
|
+
},
|
|
147
|
+
body: body != null ? JSON.stringify(body) : undefined,
|
|
148
|
+
signal,
|
|
98
149
|
});
|
|
99
|
-
|
|
150
|
+
yield* this.parseSSE(resp);
|
|
100
151
|
}
|
|
101
|
-
async *
|
|
152
|
+
async *streamSSEWithSignal(path, params, signal) {
|
|
102
153
|
const url = this.buildUrl(path, params);
|
|
103
154
|
const resp = await fetch(url, {
|
|
104
155
|
method: "GET",
|
|
105
156
|
headers: {
|
|
106
|
-
...this.
|
|
157
|
+
...this.authHeaders,
|
|
107
158
|
Accept: "text/event-stream",
|
|
108
159
|
},
|
|
160
|
+
signal,
|
|
109
161
|
});
|
|
162
|
+
yield* this.parseSSE(resp);
|
|
163
|
+
}
|
|
164
|
+
buildUrl(path, params) {
|
|
165
|
+
const url = new URL(path, this.config.apiUrl);
|
|
166
|
+
if (params) {
|
|
167
|
+
for (const [key, val] of Object.entries(params)) {
|
|
168
|
+
url.searchParams.set(key, val);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return url.toString();
|
|
172
|
+
}
|
|
173
|
+
async handle(resp) {
|
|
110
174
|
if (!resp.ok) {
|
|
111
|
-
|
|
175
|
+
const msg = await this.errorMessage(resp);
|
|
176
|
+
throw new SandboxError(`API error ${resp.status}: ${msg}`);
|
|
177
|
+
}
|
|
178
|
+
if (resp.status === 204) {
|
|
179
|
+
return undefined;
|
|
180
|
+
}
|
|
181
|
+
const contentType = resp.headers.get("content-type") || "";
|
|
182
|
+
if (contentType.includes("application/json")) {
|
|
183
|
+
return resp.json();
|
|
184
|
+
}
|
|
185
|
+
return (await resp.text());
|
|
186
|
+
}
|
|
187
|
+
async *parseSSE(resp) {
|
|
188
|
+
if (!resp.ok) {
|
|
189
|
+
throw new StreamError(`Stream error ${resp.status}: ${await this.errorMessage(resp)}`);
|
|
112
190
|
}
|
|
113
191
|
const reader = resp.body?.getReader();
|
|
114
192
|
if (!reader)
|
|
@@ -139,27 +217,25 @@ export class HTTPClient {
|
|
|
139
217
|
reader.releaseLock();
|
|
140
218
|
}
|
|
141
219
|
}
|
|
142
|
-
|
|
143
|
-
const
|
|
144
|
-
if (
|
|
145
|
-
|
|
146
|
-
|
|
220
|
+
async errorMessage(resp) {
|
|
221
|
+
const raw = await resp.text();
|
|
222
|
+
if (!raw)
|
|
223
|
+
return "request failed";
|
|
224
|
+
try {
|
|
225
|
+
const parsed = JSON.parse(raw);
|
|
226
|
+
if (typeof parsed === "string")
|
|
227
|
+
return parsed;
|
|
228
|
+
if (parsed && typeof parsed === "object") {
|
|
229
|
+
const obj = parsed;
|
|
230
|
+
if (typeof obj.message === "string")
|
|
231
|
+
return obj.message;
|
|
232
|
+
if (typeof obj.error === "string")
|
|
233
|
+
return obj.error;
|
|
147
234
|
}
|
|
235
|
+
return raw;
|
|
148
236
|
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
async handle(resp) {
|
|
152
|
-
if (!resp.ok) {
|
|
153
|
-
let msg;
|
|
154
|
-
try {
|
|
155
|
-
const body = await resp.json();
|
|
156
|
-
msg = body.message || body.error || JSON.stringify(body);
|
|
157
|
-
}
|
|
158
|
-
catch {
|
|
159
|
-
msg = await resp.text();
|
|
160
|
-
}
|
|
161
|
-
throw new SandboxError(`API error ${resp.status}: ${msg}`);
|
|
237
|
+
catch {
|
|
238
|
+
return raw;
|
|
162
239
|
}
|
|
163
|
-
return resp.json();
|
|
164
240
|
}
|
|
165
241
|
}
|
package/dist/command-handle.d.ts
CHANGED
package/dist/command-handle.js
CHANGED
package/dist/commands.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { HTTPClient } from "./client.js";
|
|
2
2
|
import { CommandHandle } from "./command-handle.js";
|
|
3
3
|
import type { CommandResult, ProcessInfo, RunCommandOptions } from "./models.js";
|
|
4
|
+
/** Command execution namespace for a single sandbox. */
|
|
4
5
|
export declare class Commands {
|
|
5
6
|
private sandboxId;
|
|
6
7
|
private client;
|
package/dist/commands.js
CHANGED
package/dist/config.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
/** Connection options for OmniRun API calls. */
|
|
1
2
|
export interface ConnectionConfig {
|
|
2
3
|
apiUrl: string;
|
|
3
4
|
apiKey: string;
|
|
4
5
|
requestTimeout: number;
|
|
5
6
|
}
|
|
7
|
+
/** Resolves runtime config from explicit options, env vars, and defaults. */
|
|
6
8
|
export declare function resolveConfig(opts?: {
|
|
7
9
|
apiUrl?: string;
|
|
8
10
|
apiKey?: string;
|
package/dist/config.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
/** Resolves runtime config from explicit options, env vars, and defaults. */
|
|
1
2
|
export function resolveConfig(opts) {
|
|
2
3
|
return {
|
|
3
4
|
apiUrl: opts?.apiUrl ||
|
|
4
5
|
(typeof process !== "undefined"
|
|
5
6
|
? process.env.OMNIRUN_API_URL
|
|
6
7
|
: undefined) ||
|
|
7
|
-
"
|
|
8
|
+
"https://api.omnirun.io",
|
|
8
9
|
apiKey: opts?.apiKey ||
|
|
9
10
|
(typeof process !== "undefined"
|
|
10
11
|
? process.env.OMNIRUN_API_KEY
|
package/dist/contexts.d.ts
CHANGED
package/dist/contexts.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/** Persistent interpreter context namespace for a single sandbox. */
|
|
1
2
|
export class Contexts {
|
|
2
3
|
sandboxId;
|
|
3
4
|
client;
|
|
@@ -59,7 +60,7 @@ export class Contexts {
|
|
|
59
60
|
const stderrParts = [];
|
|
60
61
|
const results = [];
|
|
61
62
|
let executionCount = 0;
|
|
62
|
-
for await (const event of this.client.
|
|
63
|
+
for await (const event of this.client.streamSSEPost(`${this.baseUrl}/${contextId}/stream-execute`, { code })) {
|
|
63
64
|
const e = event;
|
|
64
65
|
if (e.type === "stdout") {
|
|
65
66
|
stdoutParts.push(e.data ?? "");
|
package/dist/e2ee.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* E2EE protocol helpers (SDK-side scaffold).
|
|
3
|
+
*
|
|
4
|
+
* Current purpose:
|
|
5
|
+
* - generate client key material
|
|
6
|
+
* - send client public key during sandbox create
|
|
7
|
+
* - provide envelope encryption helpers for future encrypted endpoints
|
|
8
|
+
*/
|
|
9
|
+
export type E2EEAlgorithm = "ECDH-P256";
|
|
10
|
+
export interface E2EEKeyPairMaterial {
|
|
11
|
+
algorithm: E2EEAlgorithm;
|
|
12
|
+
publicKey: CryptoKey;
|
|
13
|
+
privateKey: CryptoKey;
|
|
14
|
+
/** Base64-encoded SPKI public key sent to OmniRun create endpoint. */
|
|
15
|
+
publicKeyBase64: string;
|
|
16
|
+
}
|
|
17
|
+
export interface E2EECreateOptions {
|
|
18
|
+
/** Enable E2EE bootstrap on sandbox create. */
|
|
19
|
+
enabled?: boolean;
|
|
20
|
+
/** Optional pre-generated keypair. If omitted, SDK generates one. */
|
|
21
|
+
keyPair?: E2EEKeyPairMaterial;
|
|
22
|
+
/** Optional explicit public key string if key material is managed externally. */
|
|
23
|
+
clientPublicKey?: string;
|
|
24
|
+
}
|
|
25
|
+
export interface E2EESessionInfo {
|
|
26
|
+
enabled: boolean;
|
|
27
|
+
clientPublicKey: string;
|
|
28
|
+
clientKeyPair?: E2EEKeyPairMaterial;
|
|
29
|
+
/** Optional server public key returned by API for handshake completion. */
|
|
30
|
+
serverPublicKey?: string;
|
|
31
|
+
}
|
|
32
|
+
export interface EncryptedEnvelope {
|
|
33
|
+
alg: "AES-256-GCM";
|
|
34
|
+
nonce: string;
|
|
35
|
+
ciphertext: string;
|
|
36
|
+
aad?: string;
|
|
37
|
+
}
|
|
38
|
+
export declare function generateE2EEKeyPair(): Promise<E2EEKeyPairMaterial>;
|
|
39
|
+
export declare function importE2EEPublicKey(publicKeyBase64: string): Promise<CryptoKey>;
|
|
40
|
+
export declare function deriveE2EESharedKey(privateKey: CryptoKey, peerPublicKeyBase64: string): Promise<CryptoKey>;
|
|
41
|
+
export declare function encryptE2EEJSON(key: CryptoKey, payload: unknown, aad?: string): Promise<EncryptedEnvelope>;
|
|
42
|
+
export declare function decryptE2EEJSON<T = unknown>(key: CryptoKey, envelope: EncryptedEnvelope): Promise<T>;
|
package/dist/e2ee.js
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* E2EE protocol helpers (SDK-side scaffold).
|
|
3
|
+
*
|
|
4
|
+
* Current purpose:
|
|
5
|
+
* - generate client key material
|
|
6
|
+
* - send client public key during sandbox create
|
|
7
|
+
* - provide envelope encryption helpers for future encrypted endpoints
|
|
8
|
+
*/
|
|
9
|
+
const ECDH_ALG = { name: "ECDH", namedCurve: "P-256" };
|
|
10
|
+
const HKDF_ALG = {
|
|
11
|
+
name: "HKDF",
|
|
12
|
+
hash: "SHA-256",
|
|
13
|
+
salt: new Uint8Array(),
|
|
14
|
+
info: new TextEncoder().encode("omnirun-e2ee-v1"),
|
|
15
|
+
};
|
|
16
|
+
function getCrypto() {
|
|
17
|
+
const c = globalThis.crypto;
|
|
18
|
+
if (!c?.subtle) {
|
|
19
|
+
throw new Error("WebCrypto is required for E2EE helpers (Node 18+ or modern browser)");
|
|
20
|
+
}
|
|
21
|
+
return c;
|
|
22
|
+
}
|
|
23
|
+
function bytesToBase64(bytes) {
|
|
24
|
+
if (typeof Buffer !== "undefined") {
|
|
25
|
+
return Buffer.from(bytes).toString("base64");
|
|
26
|
+
}
|
|
27
|
+
let binary = "";
|
|
28
|
+
for (const b of bytes)
|
|
29
|
+
binary += String.fromCharCode(b);
|
|
30
|
+
return btoa(binary);
|
|
31
|
+
}
|
|
32
|
+
function base64ToBytes(b64) {
|
|
33
|
+
if (typeof Buffer !== "undefined") {
|
|
34
|
+
return new Uint8Array(Buffer.from(b64, "base64"));
|
|
35
|
+
}
|
|
36
|
+
const binary = atob(b64);
|
|
37
|
+
const bytes = new Uint8Array(binary.length);
|
|
38
|
+
for (let i = 0; i < binary.length; i++)
|
|
39
|
+
bytes[i] = binary.charCodeAt(i);
|
|
40
|
+
return bytes;
|
|
41
|
+
}
|
|
42
|
+
function toArrayBuffer(bytes) {
|
|
43
|
+
return bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength);
|
|
44
|
+
}
|
|
45
|
+
export async function generateE2EEKeyPair() {
|
|
46
|
+
const crypto = getCrypto();
|
|
47
|
+
const keys = await crypto.subtle.generateKey(ECDH_ALG, true, ["deriveBits"]);
|
|
48
|
+
const publicKey = keys.publicKey;
|
|
49
|
+
const privateKey = keys.privateKey;
|
|
50
|
+
const spki = new Uint8Array(await crypto.subtle.exportKey("spki", publicKey));
|
|
51
|
+
return {
|
|
52
|
+
algorithm: "ECDH-P256",
|
|
53
|
+
publicKey,
|
|
54
|
+
privateKey,
|
|
55
|
+
publicKeyBase64: bytesToBase64(spki),
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
export async function importE2EEPublicKey(publicKeyBase64) {
|
|
59
|
+
const crypto = getCrypto();
|
|
60
|
+
const spki = base64ToBytes(publicKeyBase64);
|
|
61
|
+
return crypto.subtle.importKey("spki", toArrayBuffer(spki), ECDH_ALG, true, []);
|
|
62
|
+
}
|
|
63
|
+
export async function deriveE2EESharedKey(privateKey, peerPublicKeyBase64) {
|
|
64
|
+
const crypto = getCrypto();
|
|
65
|
+
const peerKey = await importE2EEPublicKey(peerPublicKeyBase64);
|
|
66
|
+
const bits = await crypto.subtle.deriveBits({ name: "ECDH", public: peerKey }, privateKey, 256);
|
|
67
|
+
const ikm = await crypto.subtle.importKey("raw", bits, "HKDF", false, ["deriveKey"]);
|
|
68
|
+
return crypto.subtle.deriveKey(HKDF_ALG, ikm, { name: "AES-GCM", length: 256 }, false, ["encrypt", "decrypt"]);
|
|
69
|
+
}
|
|
70
|
+
export async function encryptE2EEJSON(key, payload, aad) {
|
|
71
|
+
const crypto = getCrypto();
|
|
72
|
+
const iv = crypto.getRandomValues(new Uint8Array(12));
|
|
73
|
+
const plaintext = new TextEncoder().encode(JSON.stringify(payload));
|
|
74
|
+
const additionalData = aad ? new TextEncoder().encode(aad) : undefined;
|
|
75
|
+
const ivBuffer = toArrayBuffer(iv);
|
|
76
|
+
const plaintextBuffer = toArrayBuffer(plaintext);
|
|
77
|
+
const additionalDataBuffer = additionalData ? toArrayBuffer(additionalData) : undefined;
|
|
78
|
+
const ciphertext = await crypto.subtle.encrypt({
|
|
79
|
+
name: "AES-GCM",
|
|
80
|
+
iv: ivBuffer,
|
|
81
|
+
additionalData: additionalDataBuffer,
|
|
82
|
+
}, key, plaintextBuffer);
|
|
83
|
+
return {
|
|
84
|
+
alg: "AES-256-GCM",
|
|
85
|
+
nonce: bytesToBase64(iv),
|
|
86
|
+
ciphertext: bytesToBase64(new Uint8Array(ciphertext)),
|
|
87
|
+
aad,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
export async function decryptE2EEJSON(key, envelope) {
|
|
91
|
+
const crypto = getCrypto();
|
|
92
|
+
const iv = base64ToBytes(envelope.nonce);
|
|
93
|
+
const ciphertext = base64ToBytes(envelope.ciphertext);
|
|
94
|
+
const additionalData = envelope.aad
|
|
95
|
+
? new TextEncoder().encode(envelope.aad)
|
|
96
|
+
: undefined;
|
|
97
|
+
const ivBuffer = toArrayBuffer(iv);
|
|
98
|
+
const ciphertextBuffer = toArrayBuffer(ciphertext);
|
|
99
|
+
const additionalDataBuffer = additionalData ? toArrayBuffer(additionalData) : undefined;
|
|
100
|
+
const plaintext = await crypto.subtle.decrypt({
|
|
101
|
+
name: "AES-GCM",
|
|
102
|
+
iv: ivBuffer,
|
|
103
|
+
additionalData: additionalDataBuffer,
|
|
104
|
+
}, key, ciphertextBuffer);
|
|
105
|
+
const decoded = new TextDecoder().decode(new Uint8Array(plaintext));
|
|
106
|
+
return JSON.parse(decoded);
|
|
107
|
+
}
|
package/dist/exposures.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { HTTPClient } from "./client.js";
|
|
2
2
|
import type { CreateExposureOptions, ExposureInfo, RefreshExposureOptions } from "./models.js";
|
|
3
|
+
/** Preview URL management namespace for a sandbox. */
|
|
3
4
|
export declare class Exposures {
|
|
4
5
|
private sandboxId;
|
|
5
6
|
private client;
|
package/dist/exposures.js
CHANGED
package/dist/filesystem.d.ts
CHANGED
package/dist/filesystem.js
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -10,9 +10,11 @@ export { Production } from "./production.js";
|
|
|
10
10
|
export { Webhooks } from "./webhooks.js";
|
|
11
11
|
export { WatchHandle } from "./watch-handle.js";
|
|
12
12
|
export { HTTPClient } from "./client.js";
|
|
13
|
+
export { generateE2EEKeyPair, importE2EEPublicKey, deriveE2EESharedKey, encryptE2EEJSON, decryptE2EEJSON, } from "./e2ee.js";
|
|
13
14
|
export { resolveConfig } from "./config.js";
|
|
14
15
|
export type { ConnectionConfig } from "./config.js";
|
|
15
16
|
export { SandboxError, SandboxNotFoundError, CommandExitException, StreamError, TimeoutError, } from "./errors.js";
|
|
16
|
-
export type { CommandResult, EntryInfo, SandboxInfo, FullSandboxInfo, ExposureInfo, ExposureStatus, ExposureVisibility, ProcessInfo, PtyInfo, WriteEntry, FilesystemEvent, StreamEvent, RunCommandOptions, CreateSandboxOptions, CreateExposureOptions, ListSandboxOptions, RefreshExposureOptions, ContextInfo, ResultItem, LogOutput, ExecutionResult, SandboxMetrics, MetricsSnapshot, NetworkPolicy, WebhookInfo, CodeResult,
|
|
17
|
+
export type { CommandResult, EntryInfo, SandboxInfo, FullSandboxInfo, ExposureInfo, ExposureStatus, ExposureVisibility, ProcessInfo, PtyInfo, WriteEntry, FilesystemEvent, StreamEvent, RunCommandOptions, CreateSandboxOptions, CreateExposureOptions, ListSandboxOptions, RefreshExposureOptions, ContextInfo, ResultItem, LogOutput, ExecutionResult, SandboxMetrics, MetricsSnapshot, NetworkPolicy, WebhookInfo, CodeResult, } from "./models.js";
|
|
18
|
+
export type { E2EEAlgorithm, E2EEKeyPairMaterial, E2EECreateOptions, E2EESessionInfo, EncryptedEnvelope, } from "./e2ee.js";
|
|
17
19
|
export type { FileReadOptions, FileWriteOptions, FileListOptions } from "./filesystem.js";
|
|
18
20
|
export type { ExecuteOptions } from "./contexts.js";
|
package/dist/index.js
CHANGED
|
@@ -10,5 +10,6 @@ export { Production } from "./production.js";
|
|
|
10
10
|
export { Webhooks } from "./webhooks.js";
|
|
11
11
|
export { WatchHandle } from "./watch-handle.js";
|
|
12
12
|
export { HTTPClient } from "./client.js";
|
|
13
|
+
export { generateE2EEKeyPair, importE2EEPublicKey, deriveE2EESharedKey, encryptE2EEJSON, decryptE2EEJSON, } from "./e2ee.js";
|
|
13
14
|
export { resolveConfig } from "./config.js";
|
|
14
15
|
export { SandboxError, SandboxNotFoundError, CommandExitException, StreamError, TimeoutError, } from "./errors.js";
|
package/dist/models.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { E2EECreateOptions } from "./e2ee.js";
|
|
1
2
|
export interface CommandResult {
|
|
2
3
|
stdout: string;
|
|
3
4
|
stderr: string;
|
|
@@ -16,7 +17,6 @@ export interface SandboxInfo {
|
|
|
16
17
|
templateId: string;
|
|
17
18
|
status: string;
|
|
18
19
|
startedAt: string;
|
|
19
|
-
/** ISO timestamp when the sandbox expires. Absent for permanent sandboxes (timeout=0). */
|
|
20
20
|
endAt?: string;
|
|
21
21
|
name?: string;
|
|
22
22
|
state?: string;
|
|
@@ -90,20 +90,6 @@ export interface CreateExposureOptions {
|
|
|
90
90
|
export interface RefreshExposureOptions {
|
|
91
91
|
ttlSeconds?: number;
|
|
92
92
|
}
|
|
93
|
-
export interface SandboxHistoryInfo {
|
|
94
|
-
sandboxId: string;
|
|
95
|
-
accountId?: string;
|
|
96
|
-
templateId: string;
|
|
97
|
-
status: string;
|
|
98
|
-
cpuCount: number;
|
|
99
|
-
memoryMB: number;
|
|
100
|
-
metadata?: Record<string, string>;
|
|
101
|
-
createdAt: string;
|
|
102
|
-
startedAt?: string;
|
|
103
|
-
stoppedAt?: string;
|
|
104
|
-
timeoutSeconds: number;
|
|
105
|
-
createdBy?: string;
|
|
106
|
-
}
|
|
107
93
|
export interface RunCommandOptions {
|
|
108
94
|
cwd?: string;
|
|
109
95
|
timeout?: number;
|
|
@@ -126,8 +112,8 @@ export interface CreateSandboxOptions {
|
|
|
126
112
|
network?: NetworkPolicy;
|
|
127
113
|
secure?: boolean;
|
|
128
114
|
maskRequestHost?: string;
|
|
129
|
-
|
|
130
|
-
|
|
115
|
+
/** Client-side E2EE bootstrap options (key generation + public key announcement). */
|
|
116
|
+
e2ee?: boolean | E2EECreateOptions;
|
|
131
117
|
}
|
|
132
118
|
export interface ListSandboxOptions {
|
|
133
119
|
apiKey?: string;
|
package/dist/production.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { HTTPClient } from "./client.js";
|
|
2
|
-
import type { NetworkPolicy, SandboxMetrics } from "./models.js";
|
|
2
|
+
import type { MetricsSnapshot, NetworkPolicy, SandboxMetrics } from "./models.js";
|
|
3
|
+
/** Production controls for pause/resume/metrics/network policy. */
|
|
3
4
|
export declare class Production {
|
|
4
5
|
private sandboxId;
|
|
5
6
|
private client;
|
|
@@ -15,6 +16,8 @@ export declare class Production {
|
|
|
15
16
|
}>;
|
|
16
17
|
/** Get usage metrics for the sandbox. */
|
|
17
18
|
metrics(): Promise<SandboxMetrics>;
|
|
19
|
+
/** Get raw metrics snapshots if the backend returns time-series data. */
|
|
20
|
+
metricsSnapshots(): Promise<MetricsSnapshot[]>;
|
|
18
21
|
/** Set network policy for the sandbox. */
|
|
19
22
|
setNetworkPolicy(policy: NetworkPolicy): Promise<void>;
|
|
20
23
|
}
|
package/dist/production.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/** Production controls for pause/resume/metrics/network policy. */
|
|
1
2
|
export class Production {
|
|
2
3
|
sandboxId;
|
|
3
4
|
client;
|
|
@@ -19,6 +20,19 @@ export class Production {
|
|
|
19
20
|
/** Get usage metrics for the sandbox. */
|
|
20
21
|
async metrics() {
|
|
21
22
|
const data = await this.client.get(`${this.baseUrl}/metrics`);
|
|
23
|
+
// Newer API shape: array of snapshots.
|
|
24
|
+
if (Array.isArray(data)) {
|
|
25
|
+
const last = data[data.length - 1] ?? {};
|
|
26
|
+
return {
|
|
27
|
+
cpuTimeMs: 0,
|
|
28
|
+
memoryUsedMb: Math.round((last.mem_used ?? 0) / (1024 * 1024)),
|
|
29
|
+
diskUsedMb: Math.round((last.disk_used ?? 0) / (1024 * 1024)),
|
|
30
|
+
networkRxKb: 0,
|
|
31
|
+
networkTxKb: 0,
|
|
32
|
+
commandCount: 0,
|
|
33
|
+
uptime: last.timestamp ?? "",
|
|
34
|
+
};
|
|
35
|
+
}
|
|
22
36
|
return {
|
|
23
37
|
cpuTimeMs: data.cpu_time_ms ?? 0,
|
|
24
38
|
memoryUsedMb: data.memory_used_mb ?? 0,
|
|
@@ -26,9 +40,24 @@ export class Production {
|
|
|
26
40
|
networkRxKb: data.network_rx_kb ?? 0,
|
|
27
41
|
networkTxKb: data.network_tx_kb ?? 0,
|
|
28
42
|
commandCount: data.command_count ?? 0,
|
|
29
|
-
uptime: data.uptime ??
|
|
43
|
+
uptime: String(data.uptime ?? ""),
|
|
30
44
|
};
|
|
31
45
|
}
|
|
46
|
+
/** Get raw metrics snapshots if the backend returns time-series data. */
|
|
47
|
+
async metricsSnapshots() {
|
|
48
|
+
const data = await this.client.get(`${this.baseUrl}/metrics`);
|
|
49
|
+
if (!Array.isArray(data))
|
|
50
|
+
return [];
|
|
51
|
+
return data.map((m) => ({
|
|
52
|
+
timestamp: m.timestamp ?? "",
|
|
53
|
+
cpuUsedPct: m.cpu_used_pct ?? 0,
|
|
54
|
+
cpuCount: m.cpu_count ?? 0,
|
|
55
|
+
memUsed: m.mem_used ?? 0,
|
|
56
|
+
memTotal: m.mem_total ?? 0,
|
|
57
|
+
diskUsed: m.disk_used ?? 0,
|
|
58
|
+
diskTotal: m.disk_total ?? 0,
|
|
59
|
+
}));
|
|
60
|
+
}
|
|
32
61
|
/** Set network policy for the sandbox. */
|
|
33
62
|
async setNetworkPolicy(policy) {
|
|
34
63
|
await this.client.post(`${this.baseUrl}/network-policy`, {
|
package/dist/pty.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { HTTPClient } from "./client.js";
|
|
2
2
|
import type { PtyInfo } from "./models.js";
|
|
3
|
+
/** PTY namespace for terminal sessions in a sandbox. */
|
|
3
4
|
export declare class Pty {
|
|
4
5
|
private sandboxId;
|
|
5
6
|
private client;
|
|
@@ -11,6 +12,7 @@ export declare class Pty {
|
|
|
11
12
|
}): Promise<PtySession>;
|
|
12
13
|
list(): Promise<PtyInfo[]>;
|
|
13
14
|
}
|
|
15
|
+
/** Handle for a single PTY session. */
|
|
14
16
|
export declare class PtySession {
|
|
15
17
|
readonly pid: number;
|
|
16
18
|
private sandboxId;
|
package/dist/pty.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/** PTY namespace for terminal sessions in a sandbox. */
|
|
1
2
|
export class Pty {
|
|
2
3
|
sandboxId;
|
|
3
4
|
client;
|
|
@@ -19,6 +20,7 @@ export class Pty {
|
|
|
19
20
|
return this.client.get(this.baseUrl);
|
|
20
21
|
}
|
|
21
22
|
}
|
|
23
|
+
/** Handle for a single PTY session. */
|
|
22
24
|
export class PtySession {
|
|
23
25
|
pid;
|
|
24
26
|
sandboxId;
|
package/dist/sandbox.d.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { Commands } from "./commands.js";
|
|
2
2
|
import { Contexts } from "./contexts.js";
|
|
3
|
-
import {
|
|
3
|
+
import { type E2EESessionInfo } from "./e2ee.js";
|
|
4
4
|
import { Filesystem } from "./filesystem.js";
|
|
5
|
-
import
|
|
5
|
+
import { Exposures } from "./exposures.js";
|
|
6
|
+
import type { CodeResult, CreateSandboxOptions, CreateExposureOptions, ExposureInfo, FullSandboxInfo, ListSandboxOptions, MetricsSnapshot, NetworkPolicy, SandboxInfo } from "./models.js";
|
|
6
7
|
import { Production } from "./production.js";
|
|
7
8
|
import { Pty } from "./pty.js";
|
|
8
9
|
import { Webhooks } from "./webhooks.js";
|
|
10
|
+
/** Cursor paginator for listing sandboxes via `x-next-token`. */
|
|
9
11
|
export declare class SandboxPaginator {
|
|
10
12
|
private client;
|
|
11
13
|
private limit;
|
|
@@ -20,6 +22,7 @@ export declare class SandboxPaginator {
|
|
|
20
22
|
get hasNext(): boolean;
|
|
21
23
|
nextItems(): Promise<SandboxInfo[]>;
|
|
22
24
|
}
|
|
25
|
+
/** Top-level sandbox abstraction covering lifecycle and nested API namespaces. */
|
|
23
26
|
export declare class Sandbox {
|
|
24
27
|
readonly sandboxId: string;
|
|
25
28
|
readonly commands: Commands;
|
|
@@ -29,6 +32,7 @@ export declare class Sandbox {
|
|
|
29
32
|
readonly exposures: Exposures;
|
|
30
33
|
readonly production: Production;
|
|
31
34
|
readonly webhooks: Webhooks;
|
|
35
|
+
e2ee: E2EESessionInfo | null;
|
|
32
36
|
trafficAccessToken: string;
|
|
33
37
|
private client;
|
|
34
38
|
private keepAliveInterval;
|
|
@@ -41,16 +45,6 @@ export declare class Sandbox {
|
|
|
41
45
|
}): Promise<Sandbox>;
|
|
42
46
|
static list(opts?: ListSandboxOptions): Promise<SandboxInfo[]>;
|
|
43
47
|
static paginate(opts?: ListSandboxOptions): SandboxPaginator;
|
|
44
|
-
static history(opts?: {
|
|
45
|
-
apiKey?: string;
|
|
46
|
-
apiUrl?: string;
|
|
47
|
-
limit?: number;
|
|
48
|
-
offset?: number;
|
|
49
|
-
}): Promise<SandboxHistoryInfo[]>;
|
|
50
|
-
static getHistory(sandboxId: string, opts?: {
|
|
51
|
-
apiKey?: string;
|
|
52
|
-
apiUrl?: string;
|
|
53
|
-
}): Promise<SandboxHistoryInfo | null>;
|
|
54
48
|
kill(): Promise<void>;
|
|
55
49
|
setTimeout(timeout: number): Promise<void>;
|
|
56
50
|
isRunning(): Promise<boolean>;
|
package/dist/sandbox.js
CHANGED
|
@@ -2,16 +2,26 @@ import { HTTPClient } from "./client.js";
|
|
|
2
2
|
import { Commands } from "./commands.js";
|
|
3
3
|
import { resolveConfig } from "./config.js";
|
|
4
4
|
import { Contexts } from "./contexts.js";
|
|
5
|
-
import {
|
|
5
|
+
import { generateE2EEKeyPair, } from "./e2ee.js";
|
|
6
6
|
import { Filesystem } from "./filesystem.js";
|
|
7
|
+
import { Exposures } from "./exposures.js";
|
|
7
8
|
import { Production } from "./production.js";
|
|
8
9
|
import { Pty } from "./pty.js";
|
|
9
10
|
import { makeCommandResult } from "./utils.js";
|
|
10
11
|
import { Webhooks } from "./webhooks.js";
|
|
12
|
+
function encodeMetadataFilter(metadata) {
|
|
13
|
+
if (!metadata)
|
|
14
|
+
return undefined;
|
|
15
|
+
const entries = Object.entries(metadata);
|
|
16
|
+
if (entries.length === 0)
|
|
17
|
+
return undefined;
|
|
18
|
+
const [key, value] = entries[0];
|
|
19
|
+
return `${key}:${value}`;
|
|
20
|
+
}
|
|
11
21
|
function parseSandboxInfo(s) {
|
|
12
22
|
return {
|
|
13
23
|
sandboxId: s.sandboxID,
|
|
14
|
-
templateId: s.templateID ?? "",
|
|
24
|
+
templateId: s.templateID ?? s.templateId ?? "",
|
|
15
25
|
status: s.state ?? "running",
|
|
16
26
|
startedAt: s.startedAt ?? "",
|
|
17
27
|
endAt: s.endAt,
|
|
@@ -21,6 +31,27 @@ function parseSandboxInfo(s) {
|
|
|
21
31
|
memoryMB: s.memoryMB,
|
|
22
32
|
};
|
|
23
33
|
}
|
|
34
|
+
function parseFullSandboxInfo(s) {
|
|
35
|
+
const base = parseSandboxInfo(s);
|
|
36
|
+
return {
|
|
37
|
+
...base,
|
|
38
|
+
templateId: base.templateId || s.templateID || s.templateId || "",
|
|
39
|
+
state: s.state ?? base.state ?? "unknown",
|
|
40
|
+
cpuCount: s.cpuCount ?? base.cpuCount ?? 0,
|
|
41
|
+
memoryMB: s.memoryMB ?? base.memoryMB ?? 0,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
function normalizeE2EEOptions(e2ee) {
|
|
45
|
+
if (!e2ee)
|
|
46
|
+
return null;
|
|
47
|
+
if (e2ee === true)
|
|
48
|
+
return { enabled: true };
|
|
49
|
+
if (typeof e2ee === "object" && (e2ee.enabled ?? true)) {
|
|
50
|
+
return { enabled: true, keyPair: e2ee.keyPair, clientPublicKey: e2ee.clientPublicKey };
|
|
51
|
+
}
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
/** Cursor paginator for listing sandboxes via `x-next-token`. */
|
|
24
55
|
export class SandboxPaginator {
|
|
25
56
|
client;
|
|
26
57
|
limit;
|
|
@@ -48,11 +79,9 @@ export class SandboxPaginator {
|
|
|
48
79
|
params.next_token = this.nextToken;
|
|
49
80
|
if (this.state)
|
|
50
81
|
params.state = this.state;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
}
|
|
82
|
+
const metadataFilter = encodeMetadataFilter(this.metadata);
|
|
83
|
+
if (metadataFilter)
|
|
84
|
+
params.metadata = metadataFilter;
|
|
56
85
|
const { data, headers } = await this.client.getWithHeaders("/sandboxes", params);
|
|
57
86
|
const sandboxes = Array.isArray(data) ? data : [];
|
|
58
87
|
const token = headers.get("x-next-token") || "";
|
|
@@ -61,6 +90,7 @@ export class SandboxPaginator {
|
|
|
61
90
|
return sandboxes.map(parseSandboxInfo);
|
|
62
91
|
}
|
|
63
92
|
}
|
|
93
|
+
/** Top-level sandbox abstraction covering lifecycle and nested API namespaces. */
|
|
64
94
|
export class Sandbox {
|
|
65
95
|
sandboxId;
|
|
66
96
|
commands;
|
|
@@ -70,6 +100,7 @@ export class Sandbox {
|
|
|
70
100
|
exposures;
|
|
71
101
|
production;
|
|
72
102
|
webhooks;
|
|
103
|
+
e2ee = null;
|
|
73
104
|
trafficAccessToken = "";
|
|
74
105
|
client;
|
|
75
106
|
keepAliveInterval = null;
|
|
@@ -95,6 +126,15 @@ export class Sandbox {
|
|
|
95
126
|
template,
|
|
96
127
|
timeout: opts?.timeout ?? 300,
|
|
97
128
|
};
|
|
129
|
+
const e2eeOpts = normalizeE2EEOptions(opts?.e2ee);
|
|
130
|
+
let e2eeKeyPair;
|
|
131
|
+
let clientPublicKey;
|
|
132
|
+
if (e2eeOpts?.enabled) {
|
|
133
|
+
e2eeKeyPair = e2eeOpts.keyPair ?? (await generateE2EEKeyPair());
|
|
134
|
+
clientPublicKey = e2eeOpts.clientPublicKey ?? e2eeKeyPair.publicKeyBase64;
|
|
135
|
+
body.e2ee = true;
|
|
136
|
+
body.clientPublicKey = clientPublicKey;
|
|
137
|
+
}
|
|
98
138
|
if (opts?.internet)
|
|
99
139
|
body.internet = true;
|
|
100
140
|
if (opts?.envVars)
|
|
@@ -109,13 +149,17 @@ export class Sandbox {
|
|
|
109
149
|
body.secure = true;
|
|
110
150
|
if (opts?.maskRequestHost)
|
|
111
151
|
body.maskRequestHost = opts.maskRequestHost;
|
|
112
|
-
if (opts?.e2ee)
|
|
113
|
-
body.e2ee = true;
|
|
114
|
-
if (opts?.clientPublicKey)
|
|
115
|
-
body.clientPublicKey = opts.clientPublicKey;
|
|
116
152
|
const data = await client.post("/sandboxes", body);
|
|
117
153
|
const sandbox = new Sandbox(data.sandboxID, client);
|
|
118
154
|
sandbox.trafficAccessToken = data.trafficToken ?? "";
|
|
155
|
+
if (e2eeOpts?.enabled && clientPublicKey) {
|
|
156
|
+
sandbox.e2ee = {
|
|
157
|
+
enabled: true,
|
|
158
|
+
clientPublicKey,
|
|
159
|
+
clientKeyPair: e2eeKeyPair,
|
|
160
|
+
serverPublicKey: data.serverPublicKey ?? data.e2ee?.serverPublicKey,
|
|
161
|
+
};
|
|
162
|
+
}
|
|
119
163
|
if (opts?.keepAlive != null) {
|
|
120
164
|
const interval = opts.keepAlive;
|
|
121
165
|
const timeout = opts.timeout ?? 300;
|
|
@@ -146,11 +190,9 @@ export class Sandbox {
|
|
|
146
190
|
params.next_token = opts.nextToken;
|
|
147
191
|
if (opts?.state)
|
|
148
192
|
params.state = opts.state;
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
}
|
|
153
|
-
}
|
|
193
|
+
const metadataFilter = encodeMetadataFilter(opts?.metadata);
|
|
194
|
+
if (metadataFilter)
|
|
195
|
+
params.metadata = metadataFilter;
|
|
154
196
|
const data = await client.get("/sandboxes", Object.keys(params).length > 0 ? params : undefined);
|
|
155
197
|
const sandboxes = Array.isArray(data) ? data : [];
|
|
156
198
|
return sandboxes.map(parseSandboxInfo);
|
|
@@ -158,27 +200,6 @@ export class Sandbox {
|
|
|
158
200
|
static paginate(opts) {
|
|
159
201
|
return new SandboxPaginator(opts);
|
|
160
202
|
}
|
|
161
|
-
static async history(opts) {
|
|
162
|
-
const config = resolveConfig(opts);
|
|
163
|
-
const client = new HTTPClient(config);
|
|
164
|
-
const params = {};
|
|
165
|
-
if (opts?.limit != null)
|
|
166
|
-
params.limit = String(opts.limit);
|
|
167
|
-
if (opts?.offset != null)
|
|
168
|
-
params.offset = String(opts.offset);
|
|
169
|
-
const data = await client.get("/sandboxes/history", Object.keys(params).length > 0 ? params : undefined);
|
|
170
|
-
return Array.isArray(data) ? data : [];
|
|
171
|
-
}
|
|
172
|
-
static async getHistory(sandboxId, opts) {
|
|
173
|
-
const config = resolveConfig(opts);
|
|
174
|
-
const client = new HTTPClient(config);
|
|
175
|
-
try {
|
|
176
|
-
return await client.get(`/sandboxes/history/${sandboxId}`);
|
|
177
|
-
}
|
|
178
|
-
catch {
|
|
179
|
-
return null;
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
203
|
async kill() {
|
|
183
204
|
if (this.keepAliveInterval) {
|
|
184
205
|
clearInterval(this.keepAliveInterval);
|
|
@@ -199,14 +220,8 @@ export class Sandbox {
|
|
|
199
220
|
}
|
|
200
221
|
}
|
|
201
222
|
async getInfo() {
|
|
202
|
-
const
|
|
203
|
-
|
|
204
|
-
return {
|
|
205
|
-
...base,
|
|
206
|
-
state: raw.state ?? "",
|
|
207
|
-
cpuCount: raw.cpuCount ?? 0,
|
|
208
|
-
memoryMB: raw.memoryMB ?? 0,
|
|
209
|
-
};
|
|
223
|
+
const data = await this.client.get(`/sandboxes/${this.sandboxId}`);
|
|
224
|
+
return parseFullSandboxInfo(data);
|
|
210
225
|
}
|
|
211
226
|
/** Execute code via the /code endpoint. */
|
|
212
227
|
async runCode(code, language = "python") {
|
package/dist/watch-handle.d.ts
CHANGED
package/dist/watch-handle.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/** Pull-based file watch stream handle backed by server-sent events. */
|
|
1
2
|
export class WatchHandle {
|
|
2
3
|
sandboxId;
|
|
3
4
|
path;
|
|
@@ -19,7 +20,7 @@ export class WatchHandle {
|
|
|
19
20
|
if (this.recursive)
|
|
20
21
|
params.recursive = "true";
|
|
21
22
|
try {
|
|
22
|
-
for await (const event of this.client.
|
|
23
|
+
for await (const event of this.client.streamSSEWithSignal(`/sandboxes/${this.sandboxId}/files/watch`, params, this.abortController.signal)) {
|
|
23
24
|
if (!this.running)
|
|
24
25
|
break;
|
|
25
26
|
const fsEvent = event;
|
package/dist/webhooks.d.ts
CHANGED
package/dist/webhooks.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@omnirun/sdk",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "TypeScript SDK for
|
|
3
|
+
"version": "0.4.0",
|
|
4
|
+
"description": "TypeScript SDK for OmniRun sandboxes",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
@@ -12,19 +12,52 @@
|
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
14
|
"files": [
|
|
15
|
-
"dist"
|
|
15
|
+
"dist",
|
|
16
|
+
"README.md",
|
|
17
|
+
"LICENSE",
|
|
18
|
+
"CHANGELOG.md"
|
|
16
19
|
],
|
|
17
20
|
"scripts": {
|
|
18
|
-
"build": "tsc",
|
|
21
|
+
"build": "tsc -p tsconfig.json",
|
|
22
|
+
"typecheck": "tsc --noEmit -p tsconfig.json",
|
|
19
23
|
"test": "vitest run",
|
|
20
|
-
"test:
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
24
|
+
"test:unit": "vitest run tests/unit tests/contract",
|
|
25
|
+
"test:integration": "RUN_OMNIRUN_INTEGRATION=1 vitest run tests/integration",
|
|
26
|
+
"test:watch": "vitest",
|
|
27
|
+
"pack:smoke": "npm pack --dry-run",
|
|
28
|
+
"examples:hosted": "npm run build && node examples/hosted/run-all.mjs",
|
|
29
|
+
"examples:hosted:preflight": "npm run build && node examples/hosted/run-all.mjs preflight",
|
|
30
|
+
"changeset": "changeset",
|
|
31
|
+
"version-packages": "changeset version",
|
|
32
|
+
"release": "changeset publish"
|
|
26
33
|
},
|
|
34
|
+
"keywords": [
|
|
35
|
+
"omnirun",
|
|
36
|
+
"sandbox",
|
|
37
|
+
"firecracker",
|
|
38
|
+
"typescript",
|
|
39
|
+
"sdk"
|
|
40
|
+
],
|
|
41
|
+
"license": "MIT",
|
|
27
42
|
"engines": {
|
|
28
43
|
"node": ">=18"
|
|
44
|
+
},
|
|
45
|
+
"publishConfig": {
|
|
46
|
+
"access": "public",
|
|
47
|
+
"provenance": true
|
|
48
|
+
},
|
|
49
|
+
"repository": {
|
|
50
|
+
"type": "git",
|
|
51
|
+
"url": "https://github.com/a14a-org/omnirun-sdk.git"
|
|
52
|
+
},
|
|
53
|
+
"bugs": {
|
|
54
|
+
"url": "https://github.com/a14a-org/omnirun-sdk/issues"
|
|
55
|
+
},
|
|
56
|
+
"homepage": "https://github.com/a14a-org/omnirun-sdk#readme",
|
|
57
|
+
"devDependencies": {
|
|
58
|
+
"@changesets/cli": "^2.29.7",
|
|
59
|
+
"@types/node": "^24.0.0",
|
|
60
|
+
"typescript": "^5.9.3",
|
|
61
|
+
"vitest": "^3.2.4"
|
|
29
62
|
}
|
|
30
63
|
}
|