computesdk 1.0.2 → 2.0.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/dist/index.d.mts CHANGED
@@ -10,7 +10,7 @@ type Runtime = 'node' | 'python';
10
10
  /**
11
11
  * Supported provider types
12
12
  */
13
- type ProviderType = 'e2b' | 'vercel' | 'cloudflare' | 'fly' | 'auto';
13
+ type ProviderType = 'e2b' | 'vercel' | 'daytona' | 'auto';
14
14
  /**
15
15
  * Sandbox status types
16
16
  */
@@ -80,9 +80,63 @@ interface SandboxConfig {
80
80
  timeout?: number;
81
81
  }
82
82
  /**
83
- * Provider specification that all providers must implement
83
+ * File system entry information
84
+ */
85
+ interface FileEntry {
86
+ /** File/directory name */
87
+ name: string;
88
+ /** Full path to the entry */
89
+ path: string;
90
+ /** Whether this is a directory */
91
+ isDirectory: boolean;
92
+ /** File size in bytes (0 for directories) */
93
+ size: number;
94
+ /** Last modified timestamp */
95
+ lastModified: Date;
96
+ }
97
+ /**
98
+ * Basic terminal session information
99
+ */
100
+ interface TerminalSession {
101
+ /** Terminal process ID */
102
+ pid: number;
103
+ /** Terminal command */
104
+ command: string;
105
+ /** Terminal status */
106
+ status: 'running' | 'exited';
107
+ /** Exit code (if exited) */
108
+ exitCode?: number;
109
+ }
110
+ /**
111
+ * File system interface for sandbox operations
112
+ */
113
+ interface SandboxFileSystem {
114
+ /** Read file contents */
115
+ readFile(path: string): Promise<string>;
116
+ /** Write file contents */
117
+ writeFile(path: string, content: string): Promise<void>;
118
+ /** Create directory */
119
+ mkdir(path: string): Promise<void>;
120
+ /** List directory contents */
121
+ readdir(path: string): Promise<FileEntry[]>;
122
+ /** Check if file/directory exists */
123
+ exists(path: string): Promise<boolean>;
124
+ /** Remove file or directory */
125
+ remove(path: string): Promise<void>;
126
+ }
127
+ /**
128
+ * Terminal operations interface for managing terminal sessions in a sandbox
84
129
  */
85
- interface ComputeSpecification {
130
+ interface SandboxTerminal {
131
+ /** Create a new interactive terminal session */
132
+ create(options?: TerminalCreateOptions): Promise<InteractiveTerminalSession>;
133
+ /** List active terminal sessions */
134
+ list(): Promise<InteractiveTerminalSession[]>;
135
+ }
136
+ /**
137
+ * Base provider specification that all providers must implement
138
+ */
139
+ interface BaseComputeSpecification {
86
140
  /** Version of the specification */
87
141
  specificationVersion: 'v1';
88
142
  /** Provider identifier */
@@ -91,26 +145,80 @@ interface ComputeSpecification {
91
145
  sandboxId: string;
92
146
  /** Execute code in the sandbox */
93
147
  doExecute(code: string, runtime?: Runtime): Promise<ExecutionResult>;
148
+ /** Execute code in a runtime environment */
149
+ runCode(code: string, runtime?: Runtime): Promise<ExecutionResult>;
150
+ /** Execute shell commands */
151
+ runCommand(command: string, args?: string[]): Promise<ExecutionResult>;
94
152
  /** Kill the sandbox */
95
153
  doKill(): Promise<void>;
96
154
  /** Get information about the sandbox */
97
155
  doGetInfo(): Promise<SandboxInfo>;
98
156
  }
99
157
  /**
100
- * The core compute sandbox interface that all providers expose
158
+ * Provider specification with filesystem support
159
+ */
160
+ interface FilesystemComputeSpecification extends BaseComputeSpecification {
161
+ /** File system operations */
162
+ readonly filesystem: SandboxFileSystem;
163
+ }
164
+ /**
165
+ * Provider specification with terminal support
101
166
  */
102
- interface ComputeSandbox {
167
+ interface TerminalComputeSpecification extends BaseComputeSpecification {
168
+ /** Terminal operations */
169
+ readonly terminal: SandboxTerminal;
170
+ }
171
+ /**
172
+ * Provider specification with full filesystem and terminal support
173
+ */
174
+ interface FullComputeSpecification extends FilesystemComputeSpecification, TerminalComputeSpecification {
175
+ }
176
+ /**
177
+ * Union type for all possible provider specifications
178
+ */
179
+ type ComputeSpecification = BaseComputeSpecification | FilesystemComputeSpecification | TerminalComputeSpecification | FullComputeSpecification;
180
+ /**
181
+ * Base compute sandbox interface that all providers expose
182
+ */
183
+ interface BaseComputeSandbox {
103
184
  /** Provider identifier */
104
185
  provider: string;
105
186
  /** Sandbox identifier */
106
187
  sandboxId: string;
107
188
  /** Execute code in the sandbox */
108
189
  execute(code: string, runtime?: Runtime): Promise<ExecutionResult>;
190
+ /** Execute code in a runtime environment */
191
+ runCode(code: string, runtime?: Runtime): Promise<ExecutionResult>;
192
+ /** Execute shell commands */
193
+ runCommand(command: string, args?: string[]): Promise<ExecutionResult>;
109
194
  /** Kill the sandbox */
110
195
  kill(): Promise<void>;
111
196
  /** Get information about the sandbox */
112
197
  getInfo(): Promise<SandboxInfo>;
113
198
  }
199
+ /**
200
+ * Compute sandbox with filesystem support
201
+ */
202
+ interface FilesystemComputeSandbox extends BaseComputeSandbox {
203
+ /** File system operations */
204
+ readonly filesystem: SandboxFileSystem;
205
+ }
206
+ /**
207
+ * Compute sandbox with terminal support
208
+ */
209
+ interface TerminalComputeSandbox extends BaseComputeSandbox {
210
+ /** Terminal operations */
211
+ readonly terminal: SandboxTerminal;
212
+ }
213
+ /**
214
+ * Compute sandbox with full filesystem and terminal support
215
+ */
216
+ interface FullComputeSandbox extends FilesystemComputeSandbox, TerminalComputeSandbox {
217
+ }
218
+ /**
219
+ * Union type for all possible compute sandbox types
220
+ */
221
+ type ComputeSandbox = BaseComputeSandbox | FilesystemComputeSandbox | TerminalComputeSandbox | FullComputeSandbox;
114
222
  /**
115
223
  * Parameters for the executeSandbox function
116
224
  */
@@ -130,13 +238,61 @@ interface ProviderRegistry {
130
238
  sandbox(id: string): ComputeSandbox;
131
239
  }
132
240
  /**
133
- * Provider factory function type
241
+ * Provider factory function type for base providers
134
242
  */
135
- type ProviderFactory = (config?: any) => ComputeSandbox;
243
+ type BaseProviderFactory = (config?: any) => BaseComputeSandbox;
244
+ /**
245
+ * Provider factory function type for filesystem providers
246
+ */
247
+ type FilesystemProviderFactory = (config?: any) => FilesystemComputeSandbox;
248
+ /**
249
+ * Provider factory function type for terminal providers
250
+ */
251
+ type TerminalProviderFactory = (config?: any) => TerminalComputeSandbox;
252
+ /**
253
+ * Provider factory function type for full-featured providers
254
+ */
255
+ type FullProviderFactory = (config?: any) => FullComputeSandbox;
256
+ /**
257
+ * Union type for all provider factory types
258
+ */
259
+ type ProviderFactory = BaseProviderFactory | FilesystemProviderFactory | TerminalProviderFactory | FullProviderFactory;
136
260
  /**
137
261
  * Provider registry map type
138
262
  */
139
263
  type ProviderMap = Record<string, ProviderFactory>;
264
+ /**
265
+ * Terminal session with PTY (pseudo-terminal) support for interactive use
266
+ */
267
+ interface InteractiveTerminalSession extends TerminalSession {
268
+ /** Terminal columns */
269
+ cols: number;
270
+ /** Terminal rows */
271
+ rows: number;
272
+ /** Data stream handler */
273
+ onData?: (data: Uint8Array) => void;
274
+ /** Exit handler */
275
+ onExit?: (exitCode: number) => void;
276
+ /** Write data to this terminal session */
277
+ write(data: Uint8Array | string): Promise<void>;
278
+ /** Resize this terminal session */
279
+ resize(cols: number, rows: number): Promise<void>;
280
+ /** Kill this terminal session */
281
+ kill(): Promise<void>;
282
+ }
283
+ /**
284
+ * Terminal creation options
285
+ */
286
+ interface TerminalCreateOptions {
287
+ /** Command to run (defaults to shell) */
288
+ command?: string;
289
+ /** Terminal columns */
290
+ cols?: number;
291
+ /** Terminal rows */
292
+ rows?: number;
293
+ /** Environment variables */
294
+ env?: Record<string, string>;
295
+ }
140
296
 
141
297
  /**
142
298
  * ComputeSDK Error Handling
@@ -293,15 +449,8 @@ declare const DEFAULT_TIMEOUT = 300000;
293
449
  declare const ENV_KEYS: {
294
450
  E2B: string;
295
451
  VERCEL: string;
296
- CLOUDFLARE: string;
297
- FLY: string;
452
+ DAYTONA: string;
298
453
  };
299
- /**
300
- * Detect if running in Cloudflare Workers environment
301
- *
302
- * @returns True if running in Cloudflare Workers
303
- */
304
- declare function isCloudflareWorkers(): boolean;
305
454
  /**
306
455
  * Detect available providers based on environment variables
307
456
  *
@@ -352,10 +501,53 @@ declare function normalizeSandboxConfig(config?: Partial<SandboxConfig>): Sandbo
352
501
  * Execute code in a sandbox
353
502
  */
354
503
  declare function executeSandbox(params: ExecuteSandboxParams): Promise<ExecutionResult>;
504
+ /**
505
+ * Parameters for the runCode function
506
+ */
507
+ interface RunCodeParams {
508
+ /** Sandbox to execute in */
509
+ sandbox: ComputeSandbox;
510
+ /** Code to execute */
511
+ code: string;
512
+ /** Runtime to use */
513
+ runtime?: Runtime;
514
+ }
515
+ /**
516
+ * Execute code in a runtime environment
517
+ */
518
+ declare function runCode(params: RunCodeParams): Promise<ExecutionResult>;
519
+ /**
520
+ * Parameters for the runCommand function
521
+ */
522
+ interface RunCommandParams {
523
+ /** Sandbox to execute in */
524
+ sandbox: ComputeSandbox;
525
+ /** Command to execute */
526
+ command: string;
527
+ /** Command arguments */
528
+ args?: string[];
529
+ }
530
+ /**
531
+ * Execute shell commands
532
+ */
533
+ declare function runCommand(params: RunCommandParams): Promise<ExecutionResult>;
534
+ /**
535
+ * Options for retry function
536
+ */
537
+ interface RetryOptions {
538
+ /** Maximum number of attempts (default: 3) */
539
+ maxAttempts?: number;
540
+ /** Base delay in milliseconds (default: 1000) */
541
+ delay?: number;
542
+ /** Backoff multiplier (default: 2) */
543
+ backoff?: number;
544
+ /** Callback called on each retry attempt */
545
+ onRetry?: (error: Error, attempt: number) => void;
546
+ }
355
547
  /**
356
548
  * Retry function with exponential backoff
357
549
  */
358
- declare function retry<T>(fn: () => Promise<T>, maxRetries?: number, baseDelay?: number): Promise<T>;
550
+ declare function retry<T>(fn: () => Promise<T>, options?: RetryOptions): Promise<T>;
359
551
 
360
552
  /**
361
553
  * ComputeSDK Provider Registry
@@ -371,19 +563,12 @@ declare function retry<T>(fn: () => Promise<T>, maxRetries?: number, baseDelay?:
371
563
  */
372
564
  declare function createComputeRegistry(providers: ProviderMap): ProviderRegistry;
373
565
 
374
- /**
375
- * ComputeSDK Base Provider
376
- *
377
- * This file contains the base provider implementation that all
378
- * specific provider implementations extend.
379
- */
380
-
381
566
  /**
382
567
  * Base implementation of the ComputeSandbox interface
383
568
  *
384
569
  * Provides common functionality and wraps provider-specific implementations.
385
570
  */
386
- declare abstract class BaseProvider implements ComputeSandbox, ComputeSpecification {
571
+ declare abstract class BaseProvider implements BaseComputeSandbox, BaseComputeSpecification {
387
572
  /** Specification version */
388
573
  readonly specificationVersion = "v1";
389
574
  /** Provider identifier */
@@ -419,6 +604,22 @@ declare abstract class BaseProvider implements ComputeSandbox, ComputeSpecificat
419
604
  * @returns Sandbox information
420
605
  */
421
606
  getInfo(): Promise<SandboxInfo>;
607
+ /**
608
+ * Execute code in a runtime environment
609
+ *
610
+ * @param code Code to execute
611
+ * @param runtime Optional runtime to use
612
+ * @returns Execution result
613
+ */
614
+ runCode(code: string, runtime?: Runtime): Promise<ExecutionResult>;
615
+ /**
616
+ * Execute shell commands
617
+ *
618
+ * @param command Command to execute
619
+ * @param args Command arguments
620
+ * @returns Execution result
621
+ */
622
+ runCommand(command: string, args?: string[]): Promise<ExecutionResult>;
422
623
  /**
423
624
  * Provider-specific implementation of code execution
424
625
  *
@@ -439,6 +640,54 @@ declare abstract class BaseProvider implements ComputeSandbox, ComputeSpecificat
439
640
  * @returns Sandbox information
440
641
  */
441
642
  abstract doGetInfo(): Promise<SandboxInfo>;
643
+ /**
644
+ * Provider-specific implementation of code execution (optional)
645
+ *
646
+ * @param code Code to execute
647
+ * @param runtime Optional runtime to use
648
+ * @returns Execution result
649
+ */
650
+ doRunCode?(code: string, runtime?: Runtime): Promise<ExecutionResult>;
651
+ /**
652
+ * Provider-specific implementation of command execution (optional)
653
+ *
654
+ * @param command Command to execute
655
+ * @param args Command arguments
656
+ * @returns Execution result
657
+ */
658
+ doRunCommand?(command: string, args: string[]): Promise<ExecutionResult>;
659
+ }
660
+ /**
661
+ * Helper class for implementing FileSystem with error handling
662
+ */
663
+ declare abstract class BaseFileSystem implements SandboxFileSystem {
664
+ protected provider: string;
665
+ protected sandboxId: string;
666
+ constructor(provider: string, sandboxId: string);
667
+ readFile(path: string): Promise<string>;
668
+ writeFile(path: string, content: string): Promise<void>;
669
+ mkdir(path: string): Promise<void>;
670
+ readdir(path: string): Promise<FileEntry[]>;
671
+ exists(path: string): Promise<boolean>;
672
+ remove(path: string): Promise<void>;
673
+ protected abstract doReadFile(path: string): Promise<string>;
674
+ protected abstract doWriteFile(path: string, content: string): Promise<void>;
675
+ protected abstract doMkdir(path: string): Promise<void>;
676
+ protected abstract doReaddir(path: string): Promise<FileEntry[]>;
677
+ protected abstract doExists(path: string): Promise<boolean>;
678
+ protected abstract doRemove(path: string): Promise<void>;
679
+ }
680
+ /**
681
+ * Helper class for implementing Terminal with error handling
682
+ */
683
+ declare abstract class BaseTerminal implements SandboxTerminal {
684
+ protected provider: string;
685
+ protected sandboxId: string;
686
+ constructor(provider: string, sandboxId: string);
687
+ create(options?: TerminalCreateOptions): Promise<InteractiveTerminalSession>;
688
+ list(): Promise<InteractiveTerminalSession[]>;
689
+ protected abstract doCreate(options?: TerminalCreateOptions): Promise<InteractiveTerminalSession>;
690
+ protected abstract doList(): Promise<InteractiveTerminalSession[]>;
442
691
  }
443
692
 
444
693
  declare class ComputeSDK {
@@ -464,4 +713,4 @@ declare class ComputeSDK {
464
713
  * isolated sandboxed environments across multiple cloud providers.
465
714
  */
466
715
 
467
- export { AuthenticationError, BaseProvider, ComputeError, ComputeSDK, type ComputeSandbox, type ComputeSpecification, ConfigurationError, type ContainerConfig, DEFAULT_TIMEOUT, ENV_KEYS, type ExecuteSandboxParams, ExecutionError, type ExecutionResult, ProviderError, type ProviderFactory, type ProviderMap, type ProviderRegistry, type ProviderType, ProviderUnavailableError, type Runtime, type SandboxConfig, type SandboxInfo, type SandboxStatus, TimeoutError, autoSelectProvider, createComputeRegistry, ComputeSDK as default, detectAvailableProviders, executeSandbox, getDefaultRuntime, isCloudflareWorkers, normalizeContainerConfig, normalizeSandboxConfig, retry, validateProviderApiKey };
716
+ export { AuthenticationError, type BaseComputeSandbox, type BaseComputeSpecification, BaseFileSystem, BaseProvider, type BaseProviderFactory, BaseTerminal, ComputeError, ComputeSDK, type ComputeSandbox, type ComputeSpecification, ConfigurationError, type ContainerConfig, DEFAULT_TIMEOUT, ENV_KEYS, type ExecuteSandboxParams, ExecutionError, type ExecutionResult, type FileEntry, type FilesystemComputeSandbox, type FilesystemComputeSpecification, type FilesystemProviderFactory, type FullComputeSandbox, type FullComputeSpecification, type FullProviderFactory, type InteractiveTerminalSession, ProviderError, type ProviderFactory, type ProviderMap, type ProviderRegistry, type ProviderType, ProviderUnavailableError, type Runtime, type SandboxConfig, type SandboxFileSystem, type SandboxInfo, type SandboxStatus, type SandboxTerminal, type TerminalComputeSandbox, type TerminalComputeSpecification, type TerminalCreateOptions, type TerminalProviderFactory, type TerminalSession, TimeoutError, autoSelectProvider, createComputeRegistry, ComputeSDK as default, detectAvailableProviders, executeSandbox, getDefaultRuntime, normalizeContainerConfig, normalizeSandboxConfig, retry, runCode, runCommand, validateProviderApiKey };