@cloudflare/sandbox 0.4.11 → 0.4.14
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/.turbo/turbo-build.log +13 -47
- package/CHANGELOG.md +44 -16
- package/Dockerfile +15 -9
- package/README.md +0 -1
- package/dist/index.d.ts +1889 -9
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3144 -65
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
- package/src/clients/base-client.ts +39 -24
- package/src/clients/command-client.ts +8 -8
- package/src/clients/file-client.ts +31 -26
- package/src/clients/git-client.ts +3 -4
- package/src/clients/index.ts +12 -16
- package/src/clients/interpreter-client.ts +51 -47
- package/src/clients/port-client.ts +10 -10
- package/src/clients/process-client.ts +11 -8
- package/src/clients/sandbox-client.ts +2 -4
- package/src/clients/types.ts +6 -2
- package/src/clients/utility-client.ts +10 -6
- package/src/errors/adapter.ts +90 -32
- package/src/errors/classes.ts +189 -64
- package/src/errors/index.ts +9 -5
- package/src/file-stream.ts +11 -6
- package/src/index.ts +22 -15
- package/src/interpreter.ts +50 -41
- package/src/request-handler.ts +24 -21
- package/src/sandbox.ts +370 -148
- package/src/security.ts +21 -6
- package/src/sse-parser.ts +4 -3
- package/src/version.ts +1 -1
- package/tests/base-client.test.ts +116 -80
- package/tests/command-client.test.ts +149 -112
- package/tests/file-client.test.ts +309 -197
- package/tests/file-stream.test.ts +24 -20
- package/tests/get-sandbox.test.ts +45 -6
- package/tests/git-client.test.ts +188 -101
- package/tests/port-client.test.ts +100 -108
- package/tests/process-client.test.ts +204 -179
- package/tests/request-handler.test.ts +117 -65
- package/tests/sandbox.test.ts +220 -68
- package/tests/sse-parser.test.ts +17 -16
- package/tests/utility-client.test.ts +79 -72
- package/tsdown.config.ts +12 -0
- package/vitest.config.ts +6 -6
- package/dist/chunk-BFVUNTP4.js +0 -104
- package/dist/chunk-BFVUNTP4.js.map +0 -1
- package/dist/chunk-EKSWCBCA.js +0 -86
- package/dist/chunk-EKSWCBCA.js.map +0 -1
- package/dist/chunk-FE4PJSRB.js +0 -7
- package/dist/chunk-FE4PJSRB.js.map +0 -1
- package/dist/chunk-JXZMAU2C.js +0 -559
- package/dist/chunk-JXZMAU2C.js.map +0 -1
- package/dist/chunk-SVWLTRHD.js +0 -2456
- package/dist/chunk-SVWLTRHD.js.map +0 -1
- package/dist/chunk-Z532A7QC.js +0 -78
- package/dist/chunk-Z532A7QC.js.map +0 -1
- package/dist/file-stream.d.ts +0 -43
- package/dist/file-stream.js +0 -9
- package/dist/file-stream.js.map +0 -1
- package/dist/interpreter.d.ts +0 -33
- package/dist/interpreter.js +0 -8
- package/dist/interpreter.js.map +0 -1
- package/dist/request-handler.d.ts +0 -18
- package/dist/request-handler.js +0 -13
- package/dist/request-handler.js.map +0 -1
- package/dist/sandbox-DWQVgVTY.d.ts +0 -603
- package/dist/sandbox.d.ts +0 -4
- package/dist/sandbox.js +0 -13
- package/dist/sandbox.js.map +0 -1
- package/dist/security.d.ts +0 -31
- package/dist/security.js +0 -13
- package/dist/security.js.map +0 -1
- package/dist/sse-parser.d.ts +0 -28
- package/dist/sse-parser.js +0 -11
- package/dist/sse-parser.js.map +0 -1
- package/dist/version.d.ts +0 -8
- package/dist/version.js +0 -7
- package/dist/version.js.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -1,603 +0,0 @@
|
|
|
1
|
-
import * as _repo_shared from '@repo/shared';
|
|
2
|
-
import { Logger, MkdirResult, WriteFileResult, ReadFileResult, DeleteFileResult, RenameFileResult, MoveFileResult, ListFilesOptions, ListFilesResult, FileExistsResult, GitCheckoutResult, CreateContextOptions, CodeContext, OutputMessage, Result, ExecutionError, PortExposeResult, PortCloseResult, PortListResult, ProcessStartResult, ProcessListResult, ProcessInfoResult, ProcessKillResult, ProcessCleanupResult, ProcessLogsResult, ISandbox, ExecOptions, ExecResult, ProcessOptions, Process, StreamOptions, SessionOptions, ExecutionSession, RunCodeOptions, ExecutionResult, SandboxOptions } from '@repo/shared';
|
|
3
|
-
import { DurableObject } from 'cloudflare:workers';
|
|
4
|
-
import { Container } from '@cloudflare/containers';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Minimal interface for container fetch functionality
|
|
8
|
-
*/
|
|
9
|
-
interface ContainerStub {
|
|
10
|
-
containerFetch(url: string, options: RequestInit, port?: number): Promise<Response>;
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Shared HTTP client configuration options
|
|
14
|
-
*/
|
|
15
|
-
interface HttpClientOptions {
|
|
16
|
-
logger?: Logger;
|
|
17
|
-
baseUrl?: string;
|
|
18
|
-
port?: number;
|
|
19
|
-
stub?: ContainerStub;
|
|
20
|
-
onCommandComplete?: (success: boolean, exitCode: number, stdout: string, stderr: string, command: string) => void;
|
|
21
|
-
onError?: (error: string, command?: string) => void;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Base response interface for all API responses
|
|
25
|
-
*/
|
|
26
|
-
interface BaseApiResponse {
|
|
27
|
-
success: boolean;
|
|
28
|
-
timestamp: string;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Legacy error response interface - deprecated, use ApiErrorResponse
|
|
32
|
-
*/
|
|
33
|
-
interface ErrorResponse {
|
|
34
|
-
error: string;
|
|
35
|
-
details?: string;
|
|
36
|
-
code?: string;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* HTTP request configuration
|
|
40
|
-
*/
|
|
41
|
-
interface RequestConfig extends RequestInit {
|
|
42
|
-
endpoint: string;
|
|
43
|
-
data?: Record<string, any>;
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Typed response handler
|
|
47
|
-
*/
|
|
48
|
-
type ResponseHandler<T> = (response: Response) => Promise<T>;
|
|
49
|
-
/**
|
|
50
|
-
* Common session-aware request interface
|
|
51
|
-
*/
|
|
52
|
-
interface SessionRequest {
|
|
53
|
-
sessionId?: string;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Abstract base class providing common HTTP functionality for all domain clients
|
|
58
|
-
*/
|
|
59
|
-
declare abstract class BaseHttpClient {
|
|
60
|
-
protected baseUrl: string;
|
|
61
|
-
protected options: HttpClientOptions;
|
|
62
|
-
protected logger: Logger;
|
|
63
|
-
constructor(options?: HttpClientOptions);
|
|
64
|
-
/**
|
|
65
|
-
* Core HTTP request method with automatic retry for container provisioning delays
|
|
66
|
-
*/
|
|
67
|
-
protected doFetch(path: string, options?: RequestInit): Promise<Response>;
|
|
68
|
-
/**
|
|
69
|
-
* Make a POST request with JSON body
|
|
70
|
-
*/
|
|
71
|
-
protected post<T>(endpoint: string, data: Record<string, any>, responseHandler?: ResponseHandler<T>): Promise<T>;
|
|
72
|
-
/**
|
|
73
|
-
* Make a GET request
|
|
74
|
-
*/
|
|
75
|
-
protected get<T>(endpoint: string, responseHandler?: ResponseHandler<T>): Promise<T>;
|
|
76
|
-
/**
|
|
77
|
-
* Make a DELETE request
|
|
78
|
-
*/
|
|
79
|
-
protected delete<T>(endpoint: string, responseHandler?: ResponseHandler<T>): Promise<T>;
|
|
80
|
-
/**
|
|
81
|
-
* Handle HTTP response with error checking and parsing
|
|
82
|
-
*/
|
|
83
|
-
protected handleResponse<T>(response: Response, customHandler?: ResponseHandler<T>): Promise<T>;
|
|
84
|
-
/**
|
|
85
|
-
* Handle error responses with consistent error throwing
|
|
86
|
-
*/
|
|
87
|
-
protected handleErrorResponse(response: Response): Promise<never>;
|
|
88
|
-
/**
|
|
89
|
-
* Create a streaming response handler for Server-Sent Events
|
|
90
|
-
*/
|
|
91
|
-
protected handleStreamResponse(response: Response): Promise<ReadableStream<Uint8Array>>;
|
|
92
|
-
/**
|
|
93
|
-
* Utility method to log successful operations
|
|
94
|
-
*/
|
|
95
|
-
protected logSuccess(operation: string, details?: string): void;
|
|
96
|
-
/**
|
|
97
|
-
* Utility method to log errors intelligently
|
|
98
|
-
* Only logs unexpected errors (5xx), not expected errors (4xx)
|
|
99
|
-
*
|
|
100
|
-
* - 4xx errors (validation, not found, conflicts): Don't log (expected client errors)
|
|
101
|
-
* - 5xx errors (server failures, internal errors): DO log (unexpected server errors)
|
|
102
|
-
*/
|
|
103
|
-
protected logError(operation: string, error: unknown): void;
|
|
104
|
-
/**
|
|
105
|
-
* Check if 503 response is from container provisioning (retryable)
|
|
106
|
-
* vs user application (not retryable)
|
|
107
|
-
*/
|
|
108
|
-
private isContainerProvisioningError;
|
|
109
|
-
private executeFetch;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Request interface for command execution
|
|
114
|
-
*/
|
|
115
|
-
interface ExecuteRequest extends SessionRequest {
|
|
116
|
-
command: string;
|
|
117
|
-
timeoutMs?: number;
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* Response interface for command execution
|
|
121
|
-
*/
|
|
122
|
-
interface ExecuteResponse extends BaseApiResponse {
|
|
123
|
-
stdout: string;
|
|
124
|
-
stderr: string;
|
|
125
|
-
exitCode: number;
|
|
126
|
-
command: string;
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* Client for command execution operations
|
|
130
|
-
*/
|
|
131
|
-
declare class CommandClient extends BaseHttpClient {
|
|
132
|
-
/**
|
|
133
|
-
* Execute a command and return the complete result
|
|
134
|
-
* @param command - The command to execute
|
|
135
|
-
* @param sessionId - The session ID for this command execution
|
|
136
|
-
* @param timeoutMs - Optional timeout in milliseconds (unlimited by default)
|
|
137
|
-
*/
|
|
138
|
-
execute(command: string, sessionId: string, timeoutMs?: number): Promise<ExecuteResponse>;
|
|
139
|
-
/**
|
|
140
|
-
* Execute a command and return a stream of events
|
|
141
|
-
* @param command - The command to execute
|
|
142
|
-
* @param sessionId - The session ID for this command execution
|
|
143
|
-
*/
|
|
144
|
-
executeStream(command: string, sessionId: string): Promise<ReadableStream<Uint8Array>>;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* Request interface for creating directories
|
|
149
|
-
*/
|
|
150
|
-
interface MkdirRequest extends SessionRequest {
|
|
151
|
-
path: string;
|
|
152
|
-
recursive?: boolean;
|
|
153
|
-
}
|
|
154
|
-
/**
|
|
155
|
-
* Request interface for writing files
|
|
156
|
-
*/
|
|
157
|
-
interface WriteFileRequest extends SessionRequest {
|
|
158
|
-
path: string;
|
|
159
|
-
content: string;
|
|
160
|
-
encoding?: string;
|
|
161
|
-
}
|
|
162
|
-
/**
|
|
163
|
-
* Request interface for reading files
|
|
164
|
-
*/
|
|
165
|
-
interface ReadFileRequest extends SessionRequest {
|
|
166
|
-
path: string;
|
|
167
|
-
encoding?: string;
|
|
168
|
-
}
|
|
169
|
-
/**
|
|
170
|
-
* Request interface for file operations (delete, rename, move)
|
|
171
|
-
*/
|
|
172
|
-
interface FileOperationRequest extends SessionRequest {
|
|
173
|
-
path: string;
|
|
174
|
-
newPath?: string;
|
|
175
|
-
}
|
|
176
|
-
/**
|
|
177
|
-
* Client for file system operations
|
|
178
|
-
*/
|
|
179
|
-
declare class FileClient extends BaseHttpClient {
|
|
180
|
-
/**
|
|
181
|
-
* Create a directory
|
|
182
|
-
* @param path - Directory path to create
|
|
183
|
-
* @param sessionId - The session ID for this operation
|
|
184
|
-
* @param options - Optional settings (recursive)
|
|
185
|
-
*/
|
|
186
|
-
mkdir(path: string, sessionId: string, options?: {
|
|
187
|
-
recursive?: boolean;
|
|
188
|
-
}): Promise<MkdirResult>;
|
|
189
|
-
/**
|
|
190
|
-
* Write content to a file
|
|
191
|
-
* @param path - File path to write to
|
|
192
|
-
* @param content - Content to write
|
|
193
|
-
* @param sessionId - The session ID for this operation
|
|
194
|
-
* @param options - Optional settings (encoding)
|
|
195
|
-
*/
|
|
196
|
-
writeFile(path: string, content: string, sessionId: string, options?: {
|
|
197
|
-
encoding?: string;
|
|
198
|
-
}): Promise<WriteFileResult>;
|
|
199
|
-
/**
|
|
200
|
-
* Read content from a file
|
|
201
|
-
* @param path - File path to read from
|
|
202
|
-
* @param sessionId - The session ID for this operation
|
|
203
|
-
* @param options - Optional settings (encoding)
|
|
204
|
-
*/
|
|
205
|
-
readFile(path: string, sessionId: string, options?: {
|
|
206
|
-
encoding?: string;
|
|
207
|
-
}): Promise<ReadFileResult>;
|
|
208
|
-
/**
|
|
209
|
-
* Stream a file using Server-Sent Events
|
|
210
|
-
* Returns a ReadableStream of SSE events containing metadata, chunks, and completion
|
|
211
|
-
* @param path - File path to stream
|
|
212
|
-
* @param sessionId - The session ID for this operation
|
|
213
|
-
*/
|
|
214
|
-
readFileStream(path: string, sessionId: string): Promise<ReadableStream<Uint8Array>>;
|
|
215
|
-
/**
|
|
216
|
-
* Delete a file
|
|
217
|
-
* @param path - File path to delete
|
|
218
|
-
* @param sessionId - The session ID for this operation
|
|
219
|
-
*/
|
|
220
|
-
deleteFile(path: string, sessionId: string): Promise<DeleteFileResult>;
|
|
221
|
-
/**
|
|
222
|
-
* Rename a file
|
|
223
|
-
* @param path - Current file path
|
|
224
|
-
* @param newPath - New file path
|
|
225
|
-
* @param sessionId - The session ID for this operation
|
|
226
|
-
*/
|
|
227
|
-
renameFile(path: string, newPath: string, sessionId: string): Promise<RenameFileResult>;
|
|
228
|
-
/**
|
|
229
|
-
* Move a file
|
|
230
|
-
* @param path - Current file path
|
|
231
|
-
* @param newPath - Destination file path
|
|
232
|
-
* @param sessionId - The session ID for this operation
|
|
233
|
-
*/
|
|
234
|
-
moveFile(path: string, newPath: string, sessionId: string): Promise<MoveFileResult>;
|
|
235
|
-
/**
|
|
236
|
-
* List files in a directory
|
|
237
|
-
* @param path - Directory path to list
|
|
238
|
-
* @param sessionId - The session ID for this operation
|
|
239
|
-
* @param options - Optional settings (recursive, includeHidden)
|
|
240
|
-
*/
|
|
241
|
-
listFiles(path: string, sessionId: string, options?: ListFilesOptions): Promise<ListFilesResult>;
|
|
242
|
-
/**
|
|
243
|
-
* Check if a file or directory exists
|
|
244
|
-
* @param path - Path to check
|
|
245
|
-
* @param sessionId - The session ID for this operation
|
|
246
|
-
*/
|
|
247
|
-
exists(path: string, sessionId: string): Promise<FileExistsResult>;
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
/**
|
|
251
|
-
* Request interface for Git checkout operations
|
|
252
|
-
*/
|
|
253
|
-
interface GitCheckoutRequest extends SessionRequest {
|
|
254
|
-
repoUrl: string;
|
|
255
|
-
branch?: string;
|
|
256
|
-
targetDir?: string;
|
|
257
|
-
}
|
|
258
|
-
/**
|
|
259
|
-
* Client for Git repository operations
|
|
260
|
-
*/
|
|
261
|
-
declare class GitClient extends BaseHttpClient {
|
|
262
|
-
/**
|
|
263
|
-
* Clone a Git repository
|
|
264
|
-
* @param repoUrl - URL of the Git repository to clone
|
|
265
|
-
* @param sessionId - The session ID for this operation
|
|
266
|
-
* @param options - Optional settings (branch, targetDir)
|
|
267
|
-
*/
|
|
268
|
-
checkout(repoUrl: string, sessionId: string, options?: {
|
|
269
|
-
branch?: string;
|
|
270
|
-
targetDir?: string;
|
|
271
|
-
}): Promise<GitCheckoutResult>;
|
|
272
|
-
/**
|
|
273
|
-
* Extract repository name from URL for default directory name
|
|
274
|
-
*/
|
|
275
|
-
private extractRepoName;
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
interface ExecutionCallbacks {
|
|
279
|
-
onStdout?: (output: OutputMessage) => void | Promise<void>;
|
|
280
|
-
onStderr?: (output: OutputMessage) => void | Promise<void>;
|
|
281
|
-
onResult?: (result: Result) => void | Promise<void>;
|
|
282
|
-
onError?: (error: ExecutionError) => void | Promise<void>;
|
|
283
|
-
}
|
|
284
|
-
declare class InterpreterClient extends BaseHttpClient {
|
|
285
|
-
private readonly maxRetries;
|
|
286
|
-
private readonly retryDelayMs;
|
|
287
|
-
createCodeContext(options?: CreateContextOptions): Promise<CodeContext>;
|
|
288
|
-
runCodeStream(contextId: string | undefined, code: string, language: string | undefined, callbacks: ExecutionCallbacks, timeoutMs?: number): Promise<void>;
|
|
289
|
-
listCodeContexts(): Promise<CodeContext[]>;
|
|
290
|
-
deleteCodeContext(contextId: string): Promise<void>;
|
|
291
|
-
/**
|
|
292
|
-
* Execute an operation with automatic retry for transient errors
|
|
293
|
-
*/
|
|
294
|
-
private executeWithRetry;
|
|
295
|
-
private isRetryableError;
|
|
296
|
-
private parseErrorResponse;
|
|
297
|
-
private readLines;
|
|
298
|
-
private parseExecutionResult;
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
/**
|
|
302
|
-
* Request interface for exposing ports
|
|
303
|
-
*/
|
|
304
|
-
interface ExposePortRequest {
|
|
305
|
-
port: number;
|
|
306
|
-
name?: string;
|
|
307
|
-
}
|
|
308
|
-
/**
|
|
309
|
-
* Request interface for unexposing ports
|
|
310
|
-
*/
|
|
311
|
-
interface UnexposePortRequest {
|
|
312
|
-
port: number;
|
|
313
|
-
}
|
|
314
|
-
/**
|
|
315
|
-
* Client for port management and preview URL operations
|
|
316
|
-
*/
|
|
317
|
-
declare class PortClient extends BaseHttpClient {
|
|
318
|
-
/**
|
|
319
|
-
* Expose a port and get a preview URL
|
|
320
|
-
* @param port - Port number to expose
|
|
321
|
-
* @param sessionId - The session ID for this operation
|
|
322
|
-
* @param name - Optional name for the port
|
|
323
|
-
*/
|
|
324
|
-
exposePort(port: number, sessionId: string, name?: string): Promise<PortExposeResult>;
|
|
325
|
-
/**
|
|
326
|
-
* Unexpose a port and remove its preview URL
|
|
327
|
-
* @param port - Port number to unexpose
|
|
328
|
-
* @param sessionId - The session ID for this operation
|
|
329
|
-
*/
|
|
330
|
-
unexposePort(port: number, sessionId: string): Promise<PortCloseResult>;
|
|
331
|
-
/**
|
|
332
|
-
* Get all currently exposed ports
|
|
333
|
-
* @param sessionId - The session ID for this operation
|
|
334
|
-
*/
|
|
335
|
-
getExposedPorts(sessionId: string): Promise<PortListResult>;
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
/**
|
|
339
|
-
* Client for background process management
|
|
340
|
-
*/
|
|
341
|
-
declare class ProcessClient extends BaseHttpClient {
|
|
342
|
-
/**
|
|
343
|
-
* Start a background process
|
|
344
|
-
* @param command - Command to execute as a background process
|
|
345
|
-
* @param sessionId - The session ID for this operation
|
|
346
|
-
* @param options - Optional settings (processId)
|
|
347
|
-
*/
|
|
348
|
-
startProcess(command: string, sessionId: string, options?: {
|
|
349
|
-
processId?: string;
|
|
350
|
-
}): Promise<ProcessStartResult>;
|
|
351
|
-
/**
|
|
352
|
-
* List all processes (sandbox-scoped, not session-scoped)
|
|
353
|
-
*/
|
|
354
|
-
listProcesses(): Promise<ProcessListResult>;
|
|
355
|
-
/**
|
|
356
|
-
* Get information about a specific process (sandbox-scoped, not session-scoped)
|
|
357
|
-
* @param processId - ID of the process to retrieve
|
|
358
|
-
*/
|
|
359
|
-
getProcess(processId: string): Promise<ProcessInfoResult>;
|
|
360
|
-
/**
|
|
361
|
-
* Kill a specific process (sandbox-scoped, not session-scoped)
|
|
362
|
-
* @param processId - ID of the process to kill
|
|
363
|
-
*/
|
|
364
|
-
killProcess(processId: string): Promise<ProcessKillResult>;
|
|
365
|
-
/**
|
|
366
|
-
* Kill all running processes (sandbox-scoped, not session-scoped)
|
|
367
|
-
*/
|
|
368
|
-
killAllProcesses(): Promise<ProcessCleanupResult>;
|
|
369
|
-
/**
|
|
370
|
-
* Get logs from a specific process (sandbox-scoped, not session-scoped)
|
|
371
|
-
* @param processId - ID of the process to get logs from
|
|
372
|
-
*/
|
|
373
|
-
getProcessLogs(processId: string): Promise<ProcessLogsResult>;
|
|
374
|
-
/**
|
|
375
|
-
* Stream logs from a specific process (sandbox-scoped, not session-scoped)
|
|
376
|
-
* @param processId - ID of the process to stream logs from
|
|
377
|
-
*/
|
|
378
|
-
streamProcessLogs(processId: string): Promise<ReadableStream<Uint8Array>>;
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
/**
|
|
382
|
-
* Response interface for ping operations
|
|
383
|
-
*/
|
|
384
|
-
interface PingResponse extends BaseApiResponse {
|
|
385
|
-
message: string;
|
|
386
|
-
uptime?: number;
|
|
387
|
-
}
|
|
388
|
-
/**
|
|
389
|
-
* Response interface for getting available commands
|
|
390
|
-
*/
|
|
391
|
-
interface CommandsResponse extends BaseApiResponse {
|
|
392
|
-
availableCommands: string[];
|
|
393
|
-
count: number;
|
|
394
|
-
}
|
|
395
|
-
/**
|
|
396
|
-
* Request interface for creating sessions
|
|
397
|
-
*/
|
|
398
|
-
interface CreateSessionRequest {
|
|
399
|
-
id: string;
|
|
400
|
-
env?: Record<string, string>;
|
|
401
|
-
cwd?: string;
|
|
402
|
-
}
|
|
403
|
-
/**
|
|
404
|
-
* Response interface for creating sessions
|
|
405
|
-
*/
|
|
406
|
-
interface CreateSessionResponse extends BaseApiResponse {
|
|
407
|
-
id: string;
|
|
408
|
-
message: string;
|
|
409
|
-
}
|
|
410
|
-
/**
|
|
411
|
-
* Client for health checks and utility operations
|
|
412
|
-
*/
|
|
413
|
-
declare class UtilityClient extends BaseHttpClient {
|
|
414
|
-
/**
|
|
415
|
-
* Ping the sandbox to check if it's responsive
|
|
416
|
-
*/
|
|
417
|
-
ping(): Promise<string>;
|
|
418
|
-
/**
|
|
419
|
-
* Get list of available commands in the sandbox environment
|
|
420
|
-
*/
|
|
421
|
-
getCommands(): Promise<string[]>;
|
|
422
|
-
/**
|
|
423
|
-
* Create a new execution session
|
|
424
|
-
* @param options - Session configuration (id, env, cwd)
|
|
425
|
-
*/
|
|
426
|
-
createSession(options: CreateSessionRequest): Promise<CreateSessionResponse>;
|
|
427
|
-
/**
|
|
428
|
-
* Get the container version
|
|
429
|
-
* Returns the version embedded in the Docker image during build
|
|
430
|
-
*/
|
|
431
|
-
getVersion(): Promise<string>;
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
/**
|
|
435
|
-
* Main sandbox client that composes all domain-specific clients
|
|
436
|
-
* Provides organized access to all sandbox functionality
|
|
437
|
-
*/
|
|
438
|
-
declare class SandboxClient {
|
|
439
|
-
readonly commands: CommandClient;
|
|
440
|
-
readonly files: FileClient;
|
|
441
|
-
readonly processes: ProcessClient;
|
|
442
|
-
readonly ports: PortClient;
|
|
443
|
-
readonly git: GitClient;
|
|
444
|
-
readonly interpreter: InterpreterClient;
|
|
445
|
-
readonly utils: UtilityClient;
|
|
446
|
-
constructor(options: HttpClientOptions);
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
declare function getSandbox(ns: DurableObjectNamespace<Sandbox>, id: string, options?: SandboxOptions): DurableObjectStub<Sandbox<unknown>>;
|
|
450
|
-
declare class Sandbox<Env = unknown> extends Container<Env> implements ISandbox {
|
|
451
|
-
defaultPort: number;
|
|
452
|
-
sleepAfter: string | number;
|
|
453
|
-
client: SandboxClient;
|
|
454
|
-
private codeInterpreter;
|
|
455
|
-
private sandboxName;
|
|
456
|
-
private baseUrl;
|
|
457
|
-
private portTokens;
|
|
458
|
-
private defaultSession;
|
|
459
|
-
envVars: Record<string, string>;
|
|
460
|
-
private logger;
|
|
461
|
-
constructor(ctx: DurableObject['ctx'], env: Env);
|
|
462
|
-
setSandboxName(name: string): Promise<void>;
|
|
463
|
-
setBaseUrl(baseUrl: string): Promise<void>;
|
|
464
|
-
setSleepAfter(sleepAfter: string | number): Promise<void>;
|
|
465
|
-
setEnvVars(envVars: Record<string, string>): Promise<void>;
|
|
466
|
-
/**
|
|
467
|
-
* Cleanup and destroy the sandbox container
|
|
468
|
-
*/
|
|
469
|
-
destroy(): Promise<void>;
|
|
470
|
-
onStart(): void;
|
|
471
|
-
/**
|
|
472
|
-
* Check if the container version matches the SDK version
|
|
473
|
-
* Logs a warning if there's a mismatch
|
|
474
|
-
*/
|
|
475
|
-
private checkVersionCompatibility;
|
|
476
|
-
onStop(): void;
|
|
477
|
-
onError(error: unknown): void;
|
|
478
|
-
fetch(request: Request): Promise<Response>;
|
|
479
|
-
private determinePort;
|
|
480
|
-
/**
|
|
481
|
-
* Ensure default session exists - lazy initialization
|
|
482
|
-
* This is called automatically by all public methods that need a session
|
|
483
|
-
*
|
|
484
|
-
* The session is persisted to Durable Object storage to survive hot reloads
|
|
485
|
-
* during development. If a session already exists in the container after reload,
|
|
486
|
-
* we reuse it instead of trying to create a new one.
|
|
487
|
-
*/
|
|
488
|
-
private ensureDefaultSession;
|
|
489
|
-
exec(command: string, options?: ExecOptions): Promise<ExecResult>;
|
|
490
|
-
/**
|
|
491
|
-
* Internal session-aware exec implementation
|
|
492
|
-
* Used by both public exec() and session wrappers
|
|
493
|
-
*/
|
|
494
|
-
private execWithSession;
|
|
495
|
-
private executeWithStreaming;
|
|
496
|
-
private mapExecuteResponseToExecResult;
|
|
497
|
-
/**
|
|
498
|
-
* Create a Process domain object from HTTP client DTO
|
|
499
|
-
* Centralizes process object creation with bound methods
|
|
500
|
-
* This eliminates duplication across startProcess, listProcesses, getProcess, and session wrappers
|
|
501
|
-
*/
|
|
502
|
-
private createProcessFromDTO;
|
|
503
|
-
startProcess(command: string, options?: ProcessOptions, sessionId?: string): Promise<Process>;
|
|
504
|
-
listProcesses(sessionId?: string): Promise<Process[]>;
|
|
505
|
-
getProcess(id: string, sessionId?: string): Promise<Process | null>;
|
|
506
|
-
killProcess(id: string, signal?: string, sessionId?: string): Promise<void>;
|
|
507
|
-
killAllProcesses(sessionId?: string): Promise<number>;
|
|
508
|
-
cleanupCompletedProcesses(sessionId?: string): Promise<number>;
|
|
509
|
-
getProcessLogs(id: string, sessionId?: string): Promise<{
|
|
510
|
-
stdout: string;
|
|
511
|
-
stderr: string;
|
|
512
|
-
processId: string;
|
|
513
|
-
}>;
|
|
514
|
-
execStream(command: string, options?: StreamOptions): Promise<ReadableStream<Uint8Array>>;
|
|
515
|
-
/**
|
|
516
|
-
* Internal session-aware execStream implementation
|
|
517
|
-
*/
|
|
518
|
-
private execStreamWithSession;
|
|
519
|
-
streamProcessLogs(processId: string, options?: {
|
|
520
|
-
signal?: AbortSignal;
|
|
521
|
-
}): Promise<ReadableStream<Uint8Array>>;
|
|
522
|
-
gitCheckout(repoUrl: string, options: {
|
|
523
|
-
branch?: string;
|
|
524
|
-
targetDir?: string;
|
|
525
|
-
sessionId?: string;
|
|
526
|
-
}): Promise<_repo_shared.GitCheckoutResult>;
|
|
527
|
-
mkdir(path: string, options?: {
|
|
528
|
-
recursive?: boolean;
|
|
529
|
-
sessionId?: string;
|
|
530
|
-
}): Promise<_repo_shared.MkdirResult>;
|
|
531
|
-
writeFile(path: string, content: string, options?: {
|
|
532
|
-
encoding?: string;
|
|
533
|
-
sessionId?: string;
|
|
534
|
-
}): Promise<_repo_shared.WriteFileResult>;
|
|
535
|
-
deleteFile(path: string, sessionId?: string): Promise<_repo_shared.DeleteFileResult>;
|
|
536
|
-
renameFile(oldPath: string, newPath: string, sessionId?: string): Promise<_repo_shared.RenameFileResult>;
|
|
537
|
-
moveFile(sourcePath: string, destinationPath: string, sessionId?: string): Promise<_repo_shared.MoveFileResult>;
|
|
538
|
-
readFile(path: string, options?: {
|
|
539
|
-
encoding?: string;
|
|
540
|
-
sessionId?: string;
|
|
541
|
-
}): Promise<_repo_shared.ReadFileResult>;
|
|
542
|
-
/**
|
|
543
|
-
* Stream a file from the sandbox using Server-Sent Events
|
|
544
|
-
* Returns a ReadableStream that can be consumed with streamFile() or collectFile() utilities
|
|
545
|
-
* @param path - Path to the file to stream
|
|
546
|
-
* @param options - Optional session ID
|
|
547
|
-
*/
|
|
548
|
-
readFileStream(path: string, options?: {
|
|
549
|
-
sessionId?: string;
|
|
550
|
-
}): Promise<ReadableStream<Uint8Array>>;
|
|
551
|
-
listFiles(path: string, options?: {
|
|
552
|
-
recursive?: boolean;
|
|
553
|
-
includeHidden?: boolean;
|
|
554
|
-
}): Promise<_repo_shared.ListFilesResult>;
|
|
555
|
-
exists(path: string, sessionId?: string): Promise<_repo_shared.FileExistsResult>;
|
|
556
|
-
exposePort(port: number, options: {
|
|
557
|
-
name?: string;
|
|
558
|
-
hostname: string;
|
|
559
|
-
}): Promise<{
|
|
560
|
-
url: string;
|
|
561
|
-
port: number;
|
|
562
|
-
name: string | undefined;
|
|
563
|
-
}>;
|
|
564
|
-
unexposePort(port: number): Promise<void>;
|
|
565
|
-
getExposedPorts(hostname: string): Promise<{
|
|
566
|
-
url: string;
|
|
567
|
-
port: number;
|
|
568
|
-
status: "active" | "inactive";
|
|
569
|
-
}[]>;
|
|
570
|
-
isPortExposed(port: number): Promise<boolean>;
|
|
571
|
-
validatePortToken(port: number, token: string): Promise<boolean>;
|
|
572
|
-
private generatePortToken;
|
|
573
|
-
private persistPortTokens;
|
|
574
|
-
private constructPreviewUrl;
|
|
575
|
-
/**
|
|
576
|
-
* Create isolated execution session for advanced use cases
|
|
577
|
-
* Returns ExecutionSession with full sandbox API bound to specific session
|
|
578
|
-
*/
|
|
579
|
-
createSession(options?: SessionOptions): Promise<ExecutionSession>;
|
|
580
|
-
/**
|
|
581
|
-
* Get an existing session by ID
|
|
582
|
-
* Returns ExecutionSession wrapper bound to the specified session
|
|
583
|
-
*
|
|
584
|
-
* This is useful for retrieving sessions across different requests/contexts
|
|
585
|
-
* without storing the ExecutionSession object (which has RPC lifecycle limitations)
|
|
586
|
-
*
|
|
587
|
-
* @param sessionId - The ID of an existing session
|
|
588
|
-
* @returns ExecutionSession wrapper bound to the session
|
|
589
|
-
*/
|
|
590
|
-
getSession(sessionId: string): Promise<ExecutionSession>;
|
|
591
|
-
/**
|
|
592
|
-
* Internal helper to create ExecutionSession wrapper for a given sessionId
|
|
593
|
-
* Used by both createSession and getSession
|
|
594
|
-
*/
|
|
595
|
-
private getSessionWrapper;
|
|
596
|
-
createCodeContext(options?: CreateContextOptions): Promise<CodeContext>;
|
|
597
|
-
runCode(code: string, options?: RunCodeOptions): Promise<ExecutionResult>;
|
|
598
|
-
runCodeStream(code: string, options?: RunCodeOptions): Promise<ReadableStream>;
|
|
599
|
-
listCodeContexts(): Promise<CodeContext[]>;
|
|
600
|
-
deleteCodeContext(contextId: string): Promise<void>;
|
|
601
|
-
}
|
|
602
|
-
|
|
603
|
-
export { type BaseApiResponse as B, CommandClient as C, type ErrorResponse as E, FileClient as F, GitClient as G, type HttpClientOptions as H, InterpreterClient as I, type MkdirRequest as M, PortClient as P, type ReadFileRequest as R, SandboxClient as S, UtilityClient as U, type WriteFileRequest as W, ProcessClient as a, Sandbox as b, type CommandsResponse as c, type ContainerStub as d, type ExecuteRequest as e, type ExecuteResponse as f, getSandbox as g, type ExposePortRequest as h, type FileOperationRequest as i, type GitCheckoutRequest as j, type PingResponse as k, type RequestConfig as l, type ResponseHandler as m, type SessionRequest as n, type UnexposePortRequest as o, type ExecutionCallbacks as p };
|
package/dist/sandbox.d.ts
DELETED
package/dist/sandbox.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Sandbox,
|
|
3
|
-
getSandbox
|
|
4
|
-
} from "./chunk-SVWLTRHD.js";
|
|
5
|
-
import "./chunk-JXZMAU2C.js";
|
|
6
|
-
import "./chunk-Z532A7QC.js";
|
|
7
|
-
import "./chunk-EKSWCBCA.js";
|
|
8
|
-
import "./chunk-FE4PJSRB.js";
|
|
9
|
-
export {
|
|
10
|
-
Sandbox,
|
|
11
|
-
getSandbox
|
|
12
|
-
};
|
|
13
|
-
//# sourceMappingURL=sandbox.js.map
|
package/dist/sandbox.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/security.d.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Security utilities for URL construction and input validation
|
|
3
|
-
*
|
|
4
|
-
* This module contains critical security functions to prevent:
|
|
5
|
-
* - URL injection attacks
|
|
6
|
-
* - SSRF (Server-Side Request Forgery) attacks
|
|
7
|
-
* - DNS rebinding attacks
|
|
8
|
-
* - Host header injection
|
|
9
|
-
* - Open redirect vulnerabilities
|
|
10
|
-
*/
|
|
11
|
-
declare class SecurityError extends Error {
|
|
12
|
-
readonly code?: string | undefined;
|
|
13
|
-
constructor(message: string, code?: string | undefined);
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Validates port numbers for sandbox services
|
|
17
|
-
* Only allows non-system ports to prevent conflicts and security issues
|
|
18
|
-
*/
|
|
19
|
-
declare function validatePort(port: number): boolean;
|
|
20
|
-
/**
|
|
21
|
-
* Sanitizes and validates sandbox IDs for DNS compliance and security
|
|
22
|
-
* Only enforces critical requirements - allows maximum developer flexibility
|
|
23
|
-
*/
|
|
24
|
-
declare function sanitizeSandboxId(id: string): string;
|
|
25
|
-
/**
|
|
26
|
-
* Validates language for code interpreter
|
|
27
|
-
* Only allows supported languages
|
|
28
|
-
*/
|
|
29
|
-
declare function validateLanguage(language: string | undefined): void;
|
|
30
|
-
|
|
31
|
-
export { SecurityError, sanitizeSandboxId, validateLanguage, validatePort };
|
package/dist/security.js
DELETED
package/dist/security.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|