@voidrun/sdk 0.0.38 → 0.0.40

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +139 -85
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -2,9 +2,33 @@
2
2
 
3
3
  A powerful, type-safe SDK for interacting with VoidRun AI Sandboxes. Execute code, manage files, watch file changes, and interact with pseudo-terminals in isolated environments.
4
4
 
5
+ The public surface is aligned with the **[VoidRun Python SDK](https://pypi.org/project/voidrun/)** (`createSandbox`, `listSandboxes`, `remove`, `runCode`, shared defaults).
6
+
5
7
  [![npm version](https://img.shields.io/npm/v/@voidrun/sdk)](https://www.npmjs.com/package/@voidrun/sdk)
6
8
  [![License: ISC](https://img.shields.io/badge/License-ISC-blue.svg)](https://opensource.org/licenses/ISC)
7
9
 
10
+ ## Table of contents
11
+
12
+ - [Features](#features)
13
+ - [Requirements](#requirements)
14
+ - [Installation](#installation)
15
+ - [Configuration](#configuration)
16
+ - [Quick start](#quick-start)
17
+ - [Core concepts](#core-concepts)
18
+ - [Code execution](#code-execution)
19
+ - [Code interpreter](#code-interpreter)
20
+ - [Background commands](#background-commands)
21
+ - [File operations](#file-operations)
22
+ - [File watching](#file-watching)
23
+ - [Pseudo-terminal (PTY)](#pseudo-terminal-pty)
24
+ - [API reference](#api-reference)
25
+ - [Examples](#examples)
26
+ - [Error handling](#error-handling)
27
+ - [Testing and examples runner](#testing-and-examples-runner)
28
+ - [Building from source](#building-from-source)
29
+ - [Publishing](#publishing)
30
+ - [Troubleshooting](#troubleshooting)
31
+
8
32
  ## Features
9
33
 
10
34
  - 🏗️ **Sandbox Management** - Create, list, start, stop, pause, resume, and remove sandboxes
@@ -15,7 +39,12 @@ A powerful, type-safe SDK for interacting with VoidRun AI Sandboxes. Execute cod
15
39
  - 🧠 **Code Interpreter** - Easy multi-language code execution (Python, JavaScript, Bash)
16
40
  - ⚡ **Background Commands** - Run, list, kill, and attach to background processes
17
41
  - 🔐 **Type-Safe** - Full TypeScript support with generated types from OpenAPI
18
- - 🎯 **Promise-aokd** - Modern async/await API
42
+ - 🎯 **Async/await** - Promise-based API throughout
43
+
44
+ ## Requirements
45
+
46
+ - **Node.js** 18+ recommended (ESM package; Node 20+ for `tsx` examples)
47
+ - TypeScript 5.x when compiling from source
19
48
 
20
49
  ## Installation
21
50
 
@@ -29,30 +58,48 @@ Or with yarn:
29
58
  yarn add @voidrun/sdk
30
59
  ```
31
60
 
32
- ## Quick Start
61
+ ## Configuration
62
+
63
+ `VoidRun` requires an **API key**. On the hosted platform the **base URL** defaults to **`BASE_PATH`** (see `src/api-client/runtime.ts`: `https://platform.void-run.com/api` without a trailing slash). Set **`VR_API_URL`** or pass **`baseUrl`** only when you target a **self-hosted** API.
64
+
65
+ ```typescript
66
+ import { VoidRun } from "@voidrun/sdk";
67
+
68
+ const vr = new VoidRun({
69
+ apiKey: process.env.VR_API_KEY!, // or pass a string literal
70
+ });
71
+ ```
72
+
73
+ | Environment variable | Purpose |
74
+ |--------------------|---------|
75
+ | `VR_API_KEY` | API key when not passed to the constructor. |
76
+ | `VR_API_URL` | *(Self-hosted only.)* Overrides the packaged default API base URL. |
77
+
78
+ **`createSandbox` defaults** (when you omit fields) match the Python SDK: image `code`, **1** CPU, **1024** MB memory.
33
79
 
34
- ### Basic Usage
80
+ For **self-hosted** VoidRun, set **`VR_API_URL`** (or **`baseUrl`**) to your instance’s API root (including `/api` if that is how your server is mounted).
81
+
82
+ ## Quick start
83
+
84
+ ### Basic usage
35
85
 
36
86
  ```typescript
37
87
  import { VoidRun } from "@voidrun/sdk";
38
88
 
39
- // Initialize the SDK with your credentials
40
89
  const vr = new VoidRun({
41
90
  apiKey: "your-api-key-here",
42
91
  });
43
92
 
44
- // Create a sandbox
45
93
  const sandbox = await vr.createSandbox({});
46
94
 
47
- // Execute a command
95
+ // Exec returns ExecResponse: stdout/stderr/exitCode live on .data (ExecResponseData)
48
96
  const result = await sandbox.exec({ command: 'echo "Hello from VoidRun"' });
49
97
  console.log(result.data?.stdout);
50
98
 
51
- // Clean up
52
99
  await sandbox.remove();
53
100
  ```
54
101
 
55
- ## Core Concepts
102
+ ## Core concepts
56
103
 
57
104
  ### Sandboxes
58
105
 
@@ -88,11 +135,13 @@ await sandbox.resume(); // Resume a paused sandbox
88
135
  await sandbox.remove();
89
136
  ```
90
137
 
91
- ### Code Execution
138
+ ### Code execution
92
139
 
93
140
  Execute commands and capture output, errors, and exit codes.
94
141
 
95
- #### Synchronous Execution
142
+ Non-streaming **`exec`** resolves to an **`ExecResponse`** from the OpenAPI client: use **`result.data`** for **`ExecResponseData`** (`stdout`, `stderr`, `exitCode`).
143
+
144
+ #### Synchronous execution
96
145
 
97
146
  ```typescript
98
147
  const result = await sandbox.exec({ command: "ls -la /home" });
@@ -102,7 +151,7 @@ console.log(result.data?.stderr); // standard error
102
151
  console.log(result.data?.exitCode); // exit code
103
152
  ```
104
153
 
105
- #### Streaming Execution (SSE)
154
+ #### Streaming execution (SSE)
106
155
 
107
156
  For real-time output, provide streaming handlers:
108
157
 
@@ -118,7 +167,7 @@ await sandbox.exec({
118
167
  });
119
168
  ```
120
169
 
121
- #### Execution with Options
170
+ #### Execution with options
122
171
 
123
172
  ```typescript
124
173
  const result = await sandbox.exec({
@@ -129,7 +178,7 @@ const result = await sandbox.exec({
129
178
  });
130
179
  ```
131
180
 
132
- ### Code Interpreter
181
+ ### Code interpreter
133
182
 
134
183
  Execute code in multiple programming languages with a simple, intuitive API.
135
184
 
@@ -160,7 +209,7 @@ console.log(streamResult.logs); // { stdout: [...], stderr: [...] }
160
209
 
161
210
  **Supported Languages:** `python`, `javascript`, `typescript`, `node`, `bash`, `sh`
162
211
 
163
- ### Background Commands
212
+ ### Background commands
164
213
 
165
214
  Run long-running processes in the background and manage them.
166
215
 
@@ -194,7 +243,7 @@ const killResult = await sandbox.commands.kill(runResult.pid);
194
243
  console.log(killResult.success);
195
244
  ```
196
245
 
197
- ### File Operations
246
+ ### File operations
198
247
 
199
248
  Create, read, update, and manage files in the sandbox.
200
249
 
@@ -262,7 +311,7 @@ console.log(archive.archivePath || archive.data?.archivePath);
262
311
  await sandbox.fs.extractArchive("/tmp/archive.tar.gz", "/tmp/extracted");
263
312
  ```
264
313
 
265
- ### File Watching
314
+ ### File watching
266
315
 
267
316
  Monitor file changes in real-time.
268
317
 
@@ -284,11 +333,11 @@ const watcher = await sandbox.fs.watch("/app", {
284
333
  watcher.close();
285
334
  ```
286
335
 
287
- ### Pseudo-Terminal (PTY)
336
+ ### Pseudo-terminal (PTY)
288
337
 
289
338
  Interactive terminal sessions with two modes:
290
339
 
291
- #### Ephemeral Sessions (Temporary)
340
+ #### Ephemeral sessions (temporary)
292
341
 
293
342
  ```typescript
294
343
  // No session management - temporary shell
@@ -309,10 +358,10 @@ pty.sendInput("pwd\n");
309
358
  pty.close();
310
359
  ```
311
360
 
312
- #### Persistent Sessions
361
+ #### Persistent sessions
313
362
 
314
363
  ```typescript
315
- // Create a persistent session
364
+ // Create a persistent session (CreatePTYSession200Response)
316
365
  const response = await sandbox.pty.createSession();
317
366
  const sessionId = response.data?.sessionId;
318
367
 
@@ -339,7 +388,7 @@ const reconnected = await sandbox.pty.connect({
339
388
  });
340
389
  ```
341
390
 
342
- #### Interactive Commands
391
+ #### Interactive commands
343
392
 
344
393
  Run commands with automatic prompt detection:
345
394
 
@@ -354,13 +403,13 @@ const output = await pty.runCommand("ls -la", {
354
403
  console.log("Output:", output);
355
404
  ```
356
405
 
357
- #### Resize Terminal
406
+ #### Resize terminal
358
407
 
359
408
  ```typescript
360
409
  pty.resize(80, 24); // columns, rows
361
410
  ```
362
411
 
363
- #### Session Management
412
+ #### Session management
364
413
 
365
414
  ```typescript
366
415
  // List all sessions
@@ -370,9 +419,9 @@ const sessions = await sandbox.pty.list();
370
419
  await sandbox.pty.deleteSession(sessionId);
371
420
  ```
372
421
 
373
- ## API Reference
422
+ ## API reference
374
423
 
375
- ### VoidRun Class
424
+ ### VoidRun class
376
425
 
377
426
  Main client for interacting with the API.
378
427
 
@@ -382,26 +431,25 @@ new VoidRun(options?: VoidRunConfig)
382
431
 
383
432
  **Options:**
384
433
 
385
- - `apiKey?: string` - API key (defaults to `process.env.VR_API_KEY`)
386
- - `baseUrl?: string` - Base API URL (defaults to `process.env.VR_API_URL`)
387
- - `orgId?: string` - Organization ID (optional)
434
+ - `apiKey?: string` - API key (defaults to `process.env.VR_API_KEY`; empty throws)
388
435
 
389
436
  **Methods:**
390
437
 
391
438
  - `createSandbox(options: SandboxOptions)` - Create a new sandbox
392
439
  - `name?: string` - Sandbox name
393
- - `image?: string` - Image ID
394
- - `cpu?: number` - CPU cores
395
- - `mem?: number` - Memory in MB
440
+ - `image?: string` - Image id (defaults to `code` when omitted)
441
+ - `cpu?: number` - CPU cores (default `1`)
442
+ - `mem?: number` - Memory in MB (default `1024`)
396
443
  - `orgId?: string` - Organization ID
397
444
  - `userId?: string` - User ID
398
445
  - `sync?: boolean` - Sync mode (default: true)
399
446
  - `envVars?: Record<string, string>` - Environment variables
400
- - `listSandboxes()` - List all sandboxes (returns `{ sandboxes: Sandbox[], meta }`)
447
+ - `autoSleep?: boolean`, `region?: string`, `refId?: string` - optional passthrough fields
448
+ - `listSandboxes(options?: { page?: number; limit?: number })` - Returns `{ sandboxes, meta }` where `meta` has `total`, `page`, `limit`, `totalPages`
401
449
  - `getSandbox(id: string)` - Get a specific sandbox
402
- - `removeSandbox(id: string)` - Delete a sandbox
450
+ - `removeSandbox(id: string)` - Delete a sandbox by id
403
451
 
404
- ### Sandbox Class
452
+ ### Sandbox class
405
453
 
406
454
  Represents an isolated sandbox environment.
407
455
 
@@ -416,6 +464,7 @@ Represents an isolated sandbox environment.
416
464
  - `createdBy: string` - Creator ID
417
465
  - `status: string` - Sandbox status
418
466
  - `envVars?: { [key: string]: string }` - Environment variables
467
+ - `region?: string`, `refId?: string`, `autoSleep?: boolean` - Optional metadata
419
468
  - `fs: FS` - File system interface
420
469
  - `pty: PTY` - PTY interface
421
470
  - `interpreter: CodeInterpreter` - Code interpreter
@@ -440,17 +489,20 @@ Represents an isolated sandbox environment.
440
489
  - `pause()` - Pause the sandbox
441
490
  - `resume()` - Resume the sandbox
442
491
  - `remove()` - Delete the sandbox
443
- - `info()` - Get sandbox information
492
+ - `info()` - Returns the same sandbox instance (`Promise<this>`)
444
493
 
445
- **Exec Response:**
494
+ **Exec response (`ExecResponse`):**
446
495
 
447
496
  ```typescript
497
+ // Returned from non-streaming exec()
448
498
  {
499
+ status?: string;
500
+ message?: string;
449
501
  data?: {
450
- stdout: string; // standard output
451
- stderr: string; // standard error
452
- exitCode: number; // exit code
453
- }
502
+ stdout?: string;
503
+ stderr?: string;
504
+ exitCode?: number;
505
+ };
454
506
  }
455
507
  ```
456
508
 
@@ -471,7 +523,7 @@ Represents an isolated sandbox environment.
471
523
  }
472
524
  ```
473
525
 
474
- ### Commands Class
526
+ ### Commands class
475
527
 
476
528
  Background process management.
477
529
 
@@ -483,7 +535,7 @@ Background process management.
483
535
  - `connect(pid: number, handlers: ProcessAttachHandlers)` - Attach to process output stream
484
536
  - `wait(pid: number)` - Wait for process to complete
485
537
 
486
- ### FileSystem Interface
538
+ ### FS (file system) class
487
539
 
488
540
  Manage files and directories.
489
541
 
@@ -508,7 +560,7 @@ Manage files and directories.
508
560
  - `folderSize(path: string)` - Get folder size
509
561
  - `watch(path: string, options: FileWatchOptions)` - Watch for file changes
510
562
 
511
- ### FileWatcher Interface
563
+ ### FileWatcher
512
564
 
513
565
  Monitor file changes in real-time.
514
566
 
@@ -524,7 +576,7 @@ Monitor file changes in real-time.
524
576
 
525
577
  - `close()` - Stop watching
526
578
 
527
- ### PTY Interface
579
+ ### PTY class
528
580
 
529
581
  Pseudo-terminal operations.
530
582
 
@@ -695,22 +747,13 @@ pty.close();
695
747
  await sandbox.remove();
696
748
  ```
697
749
 
698
- ## Configuration
699
-
700
- The SDK can be configured by passing options to the `VoidRun` constructor:
701
-
702
- ```typescript
703
- const vr = new VoidRun({
704
- apiKey: "your-api-key", // Required: Your API key
705
- orgId: "your-org-id" // Optional: Organization ID
706
- });
707
- ```
750
+ ## Error handling
708
751
 
709
- ## Error Handling
752
+ Failed HTTP calls from the generated client are thrown as an **`Error`** whose message combines status text with the API body when JSON parsing succeeds: fields **`error`**, **`details`**, and **`message`** are concatenated so you see the same hints as in the Python SDK.
710
753
 
711
754
  ```typescript
712
755
  try {
713
- const sandbox = await vr.createSandbox({ mem: 256, cpu: 0.5 });
756
+ const sandbox = await vr.createSandbox({ mem: 1024, cpu: 1 });
714
757
  // ...
715
758
  } catch (error) {
716
759
  if (error instanceof Error) {
@@ -719,36 +762,44 @@ try {
719
762
  }
720
763
  ```
721
764
 
722
- Common errors:
765
+ Common cases:
723
766
 
724
- - **Validation Error** - Invalid sandbox parameters
725
- - **Authentication Error** - Invalid or missing API key
726
- - **Not Found** - Sandbox or session doesn't exist
727
- - **Timeout** - Operation took too long
767
+ - **Validation**: Invalid sandbox parameters for your org/plan
768
+ - **Authentication**: Missing/invalid API key
769
+ - **Not found**: Wrong sandbox or session id
770
+ - **Timeout**: Network or long-running command limits
728
771
 
729
- ## Testing
772
+ ## Testing and examples runner
730
773
 
731
- Run the comprehensive test suite:
774
+ From the `ts-sdk` directory:
732
775
 
733
776
  ```bash
734
777
  npm install
735
- npx tsx example/test-sandbox-exec.ts
778
+ chmod +x scripts/run_all_examples.sh # once
779
+ ./scripts/run_all_examples.sh
780
+ ```
781
+
782
+ Each example is run with `npx tsx --env-file=.env <file>`. Create a **`.env`** with at least `VR_API_KEY=` (add **`VR_API_URL=`** only for self-hosted). The script exits with status **1** if any example fails (suitable for CI).
783
+
784
+ Run a single script:
785
+
786
+ ```bash
787
+ npx tsx --env-file=.env example/test-sandbox-exec.ts
736
788
  ```
737
789
 
738
- Available examples:
790
+ Notable scripts under `example/`:
739
791
 
740
- - `test-sandbox-exec.ts` - Command execution with streaming
741
- - `test-sandbox-fs.ts` - File system operations
742
- - `test-sandbox-lifecycle.ts` - Sandbox lifecycle management
743
- - `test-pty.ts` - PTY session management
744
- - `test-pty-comprehensive.ts` - Full PTY testing (9 scenarios)
745
- - `test-watch.ts` - File watching
746
- - `test-background-exec.ts` - Background process management
747
- - `code-interpreter-example.ts` - Code interpreter usage
748
- - `test-commonjs-import.cjs` - CommonJS import test
749
- - `test-esm-import.mjs` - ESM import test
792
+ - `test-sandbox-exec.ts`: Command execution (incl. streaming)
793
+ - `test-sandbox-fs.ts`: File system operations
794
+ - `test-sandbox-lifecycle.ts`: Sandbox lifecycle
795
+ - `test-pty.ts` / `test-pty-comprehensive.ts`: PTY
796
+ - `test-watch.ts`: File watching
797
+ - `test-background-exec.ts`: Background commands
798
+ - `test-ts-exec.ts`: TypeScript via `runCode`
799
+ - `code-interpreter-example.ts`: Interpreter workflow
800
+ - `test-commonjs-import.cjs` / `test-esm-import.mjs`: Package exports
750
801
 
751
- ## Building from Source
802
+ ## Building from source
752
803
 
753
804
  ```bash
754
805
  # Install dependencies
@@ -764,27 +815,30 @@ npm run clean
764
815
  ## Publishing
765
816
 
766
817
  ```bash
767
- # Build and publish to npm
768
- npm run publish
818
+ npm run build
819
+ npm publish --access public
769
820
  ```
770
821
 
822
+ (`prepublishOnly` in `package.json` runs a clean build and bumps the patch version: adjust your release workflow if you do not want an automatic version bump.)
823
+
771
824
  ## Troubleshooting
772
825
 
773
- ### "API key is required, either pass in constructor or in env vars"
826
+ ### "API key is required"
774
827
 
775
- Pass your API key in the constructor:
828
+ Pass the key in the constructor or set `VR_API_KEY`:
776
829
 
777
830
  ```typescript
778
- const vr = new VoidRun({
779
- apiKey: "your-api-key"
780
- });
831
+ const vr = new VoidRun({ apiKey: "your-api-key" });
781
832
  ```
782
833
 
783
- Pass in env vars(.env)
784
834
  ```bash
785
- VR_API_KEY=vr_sddfgd2353erggdfgfdgdgdfg
835
+ export VR_API_KEY="your-api-key"
786
836
  ```
787
837
 
838
+ ### "Base URL is required"
839
+
840
+ The resolved base URL is empty (for example **`VR_API_URL=`** with no value). Omit it to use the default host, or set **`VR_API_URL`** / **`baseUrl`** to your self-hosted API root.
841
+
788
842
  ### "Sandbox creation failed"
789
843
 
790
844
  Ensure your sandbox parameters are valid:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@voidrun/sdk",
3
- "version": "0.0.38",
3
+ "version": "0.0.40",
4
4
  "description": "VoidRun AI Sandbox SDK",
5
5
  "type": "module",
6
6
  "main": "./dist/cjs/index.cjs",