@langchain/daytona 0.0.1
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/LICENSE +21 -0
- package/README.md +354 -0
- package/dist/index.cjs +696 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +641 -0
- package/dist/index.d.ts +641 -0
- package/dist/index.js +689 -0
- package/dist/index.js.map +1 -0
- package/package.json +72 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,641 @@
|
|
|
1
|
+
import { Sandbox } from "@daytonaio/sdk";
|
|
2
|
+
import { BackendFactory, BaseSandbox, ExecuteResponse, FileDownloadResponse, FileUploadResponse } from "deepagents";
|
|
3
|
+
|
|
4
|
+
//#region src/types.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Type definitions for the Daytona Sandbox backend.
|
|
7
|
+
*
|
|
8
|
+
* This module contains all type definitions for the @langchain/daytona package,
|
|
9
|
+
* including options and error types.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Supported target regions for Daytona sandboxes.
|
|
13
|
+
*
|
|
14
|
+
* - `us`: United States
|
|
15
|
+
* - `eu`: Europe
|
|
16
|
+
*/
|
|
17
|
+
type DaytonaSandboxTarget = "us" | "eu";
|
|
18
|
+
/**
|
|
19
|
+
* Configuration options for creating a Daytona Sandbox.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* const options: DaytonaSandboxOptions = {
|
|
24
|
+
* language: "typescript",
|
|
25
|
+
* timeout: 300, // 5 minutes
|
|
26
|
+
* target: "us",
|
|
27
|
+
* };
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
interface DaytonaSandboxOptions {
|
|
31
|
+
/**
|
|
32
|
+
* Primary language for code execution in the sandbox.
|
|
33
|
+
*
|
|
34
|
+
* Determines the runtime environment and code execution tooling.
|
|
35
|
+
*
|
|
36
|
+
* @default "typescript"
|
|
37
|
+
*/
|
|
38
|
+
language?: "typescript" | "python" | "javascript";
|
|
39
|
+
/**
|
|
40
|
+
* Custom environment variables to set in the sandbox.
|
|
41
|
+
*
|
|
42
|
+
* These variables will be available to all commands and code executed
|
|
43
|
+
* in the sandbox.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```typescript
|
|
47
|
+
* envVars: {
|
|
48
|
+
* NODE_ENV: "development",
|
|
49
|
+
* API_KEY: "secret"
|
|
50
|
+
* }
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
envVars?: Record<string, string>;
|
|
54
|
+
/**
|
|
55
|
+
* Resource allocation for the sandbox.
|
|
56
|
+
*
|
|
57
|
+
* When specifying resources, you must also specify an `image`.
|
|
58
|
+
* Resources cannot be customized when using the default snapshot-based sandbox.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```typescript
|
|
62
|
+
* resources: { cpu: 2, memory: 4, disk: 20 }
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
resources?: {
|
|
66
|
+
/** Number of CPUs to allocate */cpu?: number; /** Amount of memory in GiB */
|
|
67
|
+
memory?: number; /** Amount of disk space in GiB */
|
|
68
|
+
disk?: number;
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Custom Docker image to use for the sandbox.
|
|
72
|
+
*
|
|
73
|
+
* When specified, creates a sandbox from this image instead of the default snapshot.
|
|
74
|
+
* This is required when you want to customize resources.
|
|
75
|
+
*
|
|
76
|
+
* @example "node:20" or "python:3.12"
|
|
77
|
+
*/
|
|
78
|
+
image?: string;
|
|
79
|
+
/**
|
|
80
|
+
* Snapshot name to use for the sandbox.
|
|
81
|
+
*
|
|
82
|
+
* When specified, creates a sandbox from this snapshot.
|
|
83
|
+
* Cannot be used together with `image`.
|
|
84
|
+
*/
|
|
85
|
+
snapshot?: string;
|
|
86
|
+
/**
|
|
87
|
+
* Target region where the sandbox will be created.
|
|
88
|
+
*
|
|
89
|
+
* @default "us"
|
|
90
|
+
*/
|
|
91
|
+
target?: DaytonaSandboxTarget;
|
|
92
|
+
/**
|
|
93
|
+
* Auto-stop interval in minutes.
|
|
94
|
+
*
|
|
95
|
+
* The sandbox will automatically stop after being idle for this duration.
|
|
96
|
+
* Set to 0 to disable auto-stop.
|
|
97
|
+
*
|
|
98
|
+
* @default 15
|
|
99
|
+
*/
|
|
100
|
+
autoStopInterval?: number;
|
|
101
|
+
/**
|
|
102
|
+
* Default timeout for command execution in seconds.
|
|
103
|
+
*
|
|
104
|
+
* @default 300 (5 minutes)
|
|
105
|
+
*/
|
|
106
|
+
timeout?: number;
|
|
107
|
+
/**
|
|
108
|
+
* Custom labels to attach to the sandbox.
|
|
109
|
+
*
|
|
110
|
+
* Labels can be used for organizing and filtering sandboxes.
|
|
111
|
+
*/
|
|
112
|
+
labels?: Record<string, string>;
|
|
113
|
+
/**
|
|
114
|
+
* Initial files to create in the sandbox after initialization.
|
|
115
|
+
*
|
|
116
|
+
* A map of file paths to their contents. Files will be created
|
|
117
|
+
* in the sandbox filesystem before any commands are executed.
|
|
118
|
+
* Parent directories are created automatically.
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* ```typescript
|
|
122
|
+
* const options: DaytonaSandboxOptions = {
|
|
123
|
+
* language: "typescript",
|
|
124
|
+
* initialFiles: {
|
|
125
|
+
* "/app/index.js": "console.log('Hello')",
|
|
126
|
+
* "/app/package.json": '{"name": "test"}',
|
|
127
|
+
* },
|
|
128
|
+
* };
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
initialFiles?: Record<string, string>;
|
|
132
|
+
/**
|
|
133
|
+
* Authentication configuration for Daytona API.
|
|
134
|
+
*
|
|
135
|
+
* ### Environment Variable Setup
|
|
136
|
+
*
|
|
137
|
+
* ```bash
|
|
138
|
+
* # Get your API key from https://app.daytona.io
|
|
139
|
+
* export DAYTONA_API_KEY=your_api_key_here
|
|
140
|
+
* ```
|
|
141
|
+
*
|
|
142
|
+
* Or pass the API key directly in this auth configuration.
|
|
143
|
+
*/
|
|
144
|
+
auth?: {
|
|
145
|
+
/**
|
|
146
|
+
* Daytona API key.
|
|
147
|
+
* If not provided, reads from `DAYTONA_API_KEY` environment variable.
|
|
148
|
+
*/
|
|
149
|
+
apiKey?: string;
|
|
150
|
+
/**
|
|
151
|
+
* Daytona API URL.
|
|
152
|
+
* If not provided, reads from `DAYTONA_API_URL` environment variable
|
|
153
|
+
* or uses the default Daytona API URL.
|
|
154
|
+
*
|
|
155
|
+
* @default "https://app.daytona.io/api"
|
|
156
|
+
*/
|
|
157
|
+
apiUrl?: string;
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Error codes for Daytona Sandbox operations.
|
|
162
|
+
*
|
|
163
|
+
* Used to identify specific error conditions and handle them appropriately.
|
|
164
|
+
*/
|
|
165
|
+
type DaytonaSandboxErrorCode = /** Sandbox has not been initialized - call initialize() first */"NOT_INITIALIZED" /** Sandbox is already initialized - cannot initialize twice */ | "ALREADY_INITIALIZED" /** Authentication failed - check API key configuration */ | "AUTHENTICATION_FAILED" /** Failed to create sandbox - check options and quotas */ | "SANDBOX_CREATION_FAILED" /** Sandbox not found - may have been deleted or expired */ | "SANDBOX_NOT_FOUND" /** Sandbox is not in started state */ | "SANDBOX_NOT_STARTED" /** Command execution timed out */ | "COMMAND_TIMEOUT" /** Command execution failed */ | "COMMAND_FAILED" /** File operation (read/write) failed */ | "FILE_OPERATION_FAILED" /** Resource limits exceeded (CPU, memory, storage) */ | "RESOURCE_LIMIT_EXCEEDED";
|
|
166
|
+
/**
|
|
167
|
+
* Custom error class for Daytona Sandbox operations.
|
|
168
|
+
*
|
|
169
|
+
* Provides structured error information including:
|
|
170
|
+
* - Human-readable message
|
|
171
|
+
* - Error code for programmatic handling
|
|
172
|
+
* - Original cause for debugging
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* ```typescript
|
|
176
|
+
* try {
|
|
177
|
+
* await sandbox.execute("some command");
|
|
178
|
+
* } catch (error) {
|
|
179
|
+
* if (error instanceof DaytonaSandboxError) {
|
|
180
|
+
* switch (error.code) {
|
|
181
|
+
* case "NOT_INITIALIZED":
|
|
182
|
+
* await sandbox.initialize();
|
|
183
|
+
* break;
|
|
184
|
+
* case "COMMAND_TIMEOUT":
|
|
185
|
+
* console.error("Command took too long");
|
|
186
|
+
* break;
|
|
187
|
+
* default:
|
|
188
|
+
* throw error;
|
|
189
|
+
* }
|
|
190
|
+
* }
|
|
191
|
+
* }
|
|
192
|
+
* ```
|
|
193
|
+
*/
|
|
194
|
+
declare class DaytonaSandboxError extends Error {
|
|
195
|
+
readonly code: DaytonaSandboxErrorCode;
|
|
196
|
+
readonly cause?: Error | undefined;
|
|
197
|
+
/** Error name for instanceof checks and logging */
|
|
198
|
+
readonly name = "DaytonaSandboxError";
|
|
199
|
+
/**
|
|
200
|
+
* Creates a new DaytonaSandboxError.
|
|
201
|
+
*
|
|
202
|
+
* @param message - Human-readable error description
|
|
203
|
+
* @param code - Structured error code for programmatic handling
|
|
204
|
+
* @param cause - Original error that caused this error (for debugging)
|
|
205
|
+
*/
|
|
206
|
+
constructor(message: string, code: DaytonaSandboxErrorCode, cause?: Error | undefined);
|
|
207
|
+
}
|
|
208
|
+
//#endregion
|
|
209
|
+
//#region src/sandbox.d.ts
|
|
210
|
+
/**
|
|
211
|
+
* Daytona Sandbox backend for deepagents.
|
|
212
|
+
*
|
|
213
|
+
* Extends `BaseSandbox` to provide command execution, file operations, and
|
|
214
|
+
* sandbox lifecycle management using Daytona's SDK.
|
|
215
|
+
*
|
|
216
|
+
* ## Basic Usage
|
|
217
|
+
*
|
|
218
|
+
* ```typescript
|
|
219
|
+
* import { DaytonaSandbox } from "@langchain/daytona";
|
|
220
|
+
*
|
|
221
|
+
* // Create and initialize a sandbox
|
|
222
|
+
* const sandbox = await DaytonaSandbox.create({
|
|
223
|
+
* language: "typescript",
|
|
224
|
+
* timeout: 300,
|
|
225
|
+
* });
|
|
226
|
+
*
|
|
227
|
+
* try {
|
|
228
|
+
* // Execute commands
|
|
229
|
+
* const result = await sandbox.execute("node --version");
|
|
230
|
+
* console.log(result.output);
|
|
231
|
+
* } finally {
|
|
232
|
+
* // Always cleanup
|
|
233
|
+
* await sandbox.close();
|
|
234
|
+
* }
|
|
235
|
+
* ```
|
|
236
|
+
*
|
|
237
|
+
* ## Using with DeepAgent
|
|
238
|
+
*
|
|
239
|
+
* ```typescript
|
|
240
|
+
* import { createDeepAgent } from "deepagents";
|
|
241
|
+
* import { DaytonaSandbox } from "@langchain/daytona";
|
|
242
|
+
*
|
|
243
|
+
* const sandbox = await DaytonaSandbox.create();
|
|
244
|
+
*
|
|
245
|
+
* const agent = createDeepAgent({
|
|
246
|
+
* model: new ChatAnthropic({ model: "claude-sonnet-4-20250514" }),
|
|
247
|
+
* systemPrompt: "You are a coding assistant with sandbox access.",
|
|
248
|
+
* backend: sandbox,
|
|
249
|
+
* });
|
|
250
|
+
* ```
|
|
251
|
+
*/
|
|
252
|
+
declare class DaytonaSandbox extends BaseSandbox {
|
|
253
|
+
#private;
|
|
254
|
+
/**
|
|
255
|
+
* Get the unique identifier for this sandbox.
|
|
256
|
+
*
|
|
257
|
+
* Before initialization, returns a temporary ID.
|
|
258
|
+
* After initialization, returns the actual Daytona sandbox ID.
|
|
259
|
+
*/
|
|
260
|
+
get id(): string;
|
|
261
|
+
/**
|
|
262
|
+
* Get the underlying Daytona Sandbox instance.
|
|
263
|
+
*
|
|
264
|
+
* @throws {DaytonaSandboxError} If the sandbox is not initialized
|
|
265
|
+
*
|
|
266
|
+
* @example
|
|
267
|
+
* ```typescript
|
|
268
|
+
* const sandbox = await DaytonaSandbox.create();
|
|
269
|
+
* const daytonaSdk = sandbox.sandbox; // Access the raw SDK
|
|
270
|
+
* ```
|
|
271
|
+
*/
|
|
272
|
+
get sandbox(): Sandbox;
|
|
273
|
+
/**
|
|
274
|
+
* Check if the sandbox is initialized and running.
|
|
275
|
+
*/
|
|
276
|
+
get isRunning(): boolean;
|
|
277
|
+
/**
|
|
278
|
+
* Create a new DaytonaSandbox instance.
|
|
279
|
+
*
|
|
280
|
+
* Note: This only creates the instance. Call `initialize()` to actually
|
|
281
|
+
* create the Daytona Sandbox, or use the static `DaytonaSandbox.create()` method.
|
|
282
|
+
*
|
|
283
|
+
* @param options - Configuration options for the sandbox
|
|
284
|
+
*
|
|
285
|
+
* @example
|
|
286
|
+
* ```typescript
|
|
287
|
+
* // Two-step initialization
|
|
288
|
+
* const sandbox = new DaytonaSandbox({ language: "typescript" });
|
|
289
|
+
* await sandbox.initialize();
|
|
290
|
+
*
|
|
291
|
+
* // Or use the factory method
|
|
292
|
+
* const sandbox = await DaytonaSandbox.create({ language: "typescript" });
|
|
293
|
+
* ```
|
|
294
|
+
*/
|
|
295
|
+
constructor(options?: DaytonaSandboxOptions);
|
|
296
|
+
/**
|
|
297
|
+
* Initialize the sandbox by creating a new Daytona Sandbox instance.
|
|
298
|
+
*
|
|
299
|
+
* This method authenticates with Daytona and provisions a new sandbox.
|
|
300
|
+
* After initialization, the `id` property will reflect the actual sandbox ID.
|
|
301
|
+
*
|
|
302
|
+
* @throws {DaytonaSandboxError} If already initialized (`ALREADY_INITIALIZED`)
|
|
303
|
+
* @throws {DaytonaSandboxError} If authentication fails (`AUTHENTICATION_FAILED`)
|
|
304
|
+
* @throws {DaytonaSandboxError} If sandbox creation fails (`SANDBOX_CREATION_FAILED`)
|
|
305
|
+
*
|
|
306
|
+
* @example
|
|
307
|
+
* ```typescript
|
|
308
|
+
* const sandbox = new DaytonaSandbox();
|
|
309
|
+
* await sandbox.initialize();
|
|
310
|
+
* console.log(`Sandbox ID: ${sandbox.id}`);
|
|
311
|
+
* ```
|
|
312
|
+
*/
|
|
313
|
+
initialize(): Promise<void>;
|
|
314
|
+
/**
|
|
315
|
+
* Execute a command in the sandbox.
|
|
316
|
+
*
|
|
317
|
+
* Commands are run using the sandbox's shell.
|
|
318
|
+
*
|
|
319
|
+
* @param command - The shell command to execute
|
|
320
|
+
* @returns Execution result with output, exit code, and truncation flag
|
|
321
|
+
* @throws {DaytonaSandboxError} If the sandbox is not initialized
|
|
322
|
+
*
|
|
323
|
+
* @example
|
|
324
|
+
* ```typescript
|
|
325
|
+
* const result = await sandbox.execute("echo 'Hello World'");
|
|
326
|
+
* console.log(result.output); // "Hello World\n"
|
|
327
|
+
* console.log(result.exitCode); // 0
|
|
328
|
+
* ```
|
|
329
|
+
*/
|
|
330
|
+
execute(command: string): Promise<ExecuteResponse>;
|
|
331
|
+
/**
|
|
332
|
+
* Upload files to the sandbox.
|
|
333
|
+
*
|
|
334
|
+
* Files are written to the sandbox filesystem. Parent directories are
|
|
335
|
+
* created automatically if they don't exist.
|
|
336
|
+
*
|
|
337
|
+
* @param files - Array of [path, content] tuples to upload
|
|
338
|
+
* @returns Upload result for each file, with success or error status
|
|
339
|
+
*
|
|
340
|
+
* @example
|
|
341
|
+
* ```typescript
|
|
342
|
+
* const encoder = new TextEncoder();
|
|
343
|
+
* const results = await sandbox.uploadFiles([
|
|
344
|
+
* ["src/index.js", encoder.encode("console.log('Hello')")],
|
|
345
|
+
* ["package.json", encoder.encode('{"name": "test"}')],
|
|
346
|
+
* ]);
|
|
347
|
+
* ```
|
|
348
|
+
*/
|
|
349
|
+
uploadFiles(files: Array<[string, Uint8Array]>): Promise<FileUploadResponse[]>;
|
|
350
|
+
/**
|
|
351
|
+
* Download files from the sandbox.
|
|
352
|
+
*
|
|
353
|
+
* Each file is read individually, allowing partial success when some
|
|
354
|
+
* files exist and others don't.
|
|
355
|
+
*
|
|
356
|
+
* @param paths - Array of file paths to download
|
|
357
|
+
* @returns Download result for each file, with content or error
|
|
358
|
+
*
|
|
359
|
+
* @example
|
|
360
|
+
* ```typescript
|
|
361
|
+
* const results = await sandbox.downloadFiles(["src/index.js", "missing.txt"]);
|
|
362
|
+
* for (const result of results) {
|
|
363
|
+
* if (result.content) {
|
|
364
|
+
* console.log(new TextDecoder().decode(result.content));
|
|
365
|
+
* } else {
|
|
366
|
+
* console.error(`Error: ${result.error}`);
|
|
367
|
+
* }
|
|
368
|
+
* }
|
|
369
|
+
* ```
|
|
370
|
+
*/
|
|
371
|
+
downloadFiles(paths: string[]): Promise<FileDownloadResponse[]>;
|
|
372
|
+
/**
|
|
373
|
+
* Close the sandbox and release all resources.
|
|
374
|
+
*
|
|
375
|
+
* After closing, the sandbox cannot be used again. The sandbox is deleted
|
|
376
|
+
* from Daytona's infrastructure.
|
|
377
|
+
*
|
|
378
|
+
* @example
|
|
379
|
+
* ```typescript
|
|
380
|
+
* try {
|
|
381
|
+
* await sandbox.execute("npm run build");
|
|
382
|
+
* } finally {
|
|
383
|
+
* await sandbox.close();
|
|
384
|
+
* }
|
|
385
|
+
* ```
|
|
386
|
+
*/
|
|
387
|
+
close(): Promise<void>;
|
|
388
|
+
/**
|
|
389
|
+
* Stop the sandbox without deleting it.
|
|
390
|
+
*
|
|
391
|
+
* The sandbox can be restarted later using `start()`.
|
|
392
|
+
*
|
|
393
|
+
* @example
|
|
394
|
+
* ```typescript
|
|
395
|
+
* await sandbox.stop();
|
|
396
|
+
* // Later...
|
|
397
|
+
* await sandbox.start();
|
|
398
|
+
* ```
|
|
399
|
+
*/
|
|
400
|
+
stop(): Promise<void>;
|
|
401
|
+
/**
|
|
402
|
+
* Start a stopped sandbox.
|
|
403
|
+
*
|
|
404
|
+
* @param timeout - Maximum time to wait in seconds (default: 60)
|
|
405
|
+
*
|
|
406
|
+
* @example
|
|
407
|
+
* ```typescript
|
|
408
|
+
* await sandbox.start();
|
|
409
|
+
* console.log("Sandbox is now running");
|
|
410
|
+
* ```
|
|
411
|
+
*/
|
|
412
|
+
start(timeout?: number): Promise<void>;
|
|
413
|
+
/**
|
|
414
|
+
* Forcefully terminate and delete the sandbox.
|
|
415
|
+
*
|
|
416
|
+
* Use this when you need to immediately stop the sandbox.
|
|
417
|
+
*
|
|
418
|
+
* @example
|
|
419
|
+
* ```typescript
|
|
420
|
+
* await sandbox.kill();
|
|
421
|
+
* ```
|
|
422
|
+
*/
|
|
423
|
+
kill(): Promise<void>;
|
|
424
|
+
/**
|
|
425
|
+
* Get the working directory path inside the sandbox.
|
|
426
|
+
*
|
|
427
|
+
* @returns The absolute path to the sandbox working directory
|
|
428
|
+
*
|
|
429
|
+
* @example
|
|
430
|
+
* ```typescript
|
|
431
|
+
* const workDir = await sandbox.getWorkDir();
|
|
432
|
+
* console.log(`Working directory: ${workDir}`);
|
|
433
|
+
* ```
|
|
434
|
+
*/
|
|
435
|
+
getWorkDir(): Promise<string>;
|
|
436
|
+
/**
|
|
437
|
+
* Get the user's home directory path inside the sandbox.
|
|
438
|
+
*
|
|
439
|
+
* @returns The absolute path to the user's home directory
|
|
440
|
+
*
|
|
441
|
+
* @example
|
|
442
|
+
* ```typescript
|
|
443
|
+
* const homeDir = await sandbox.getUserHomeDir();
|
|
444
|
+
* console.log(`Home directory: ${homeDir}`);
|
|
445
|
+
* ```
|
|
446
|
+
*/
|
|
447
|
+
getUserHomeDir(): Promise<string>;
|
|
448
|
+
/**
|
|
449
|
+
* Create and initialize a new DaytonaSandbox in one step.
|
|
450
|
+
*
|
|
451
|
+
* This is the recommended way to create a sandbox. It combines
|
|
452
|
+
* construction and initialization into a single async operation.
|
|
453
|
+
*
|
|
454
|
+
* @param options - Configuration options for the sandbox
|
|
455
|
+
* @returns An initialized and ready-to-use sandbox
|
|
456
|
+
*
|
|
457
|
+
* @example
|
|
458
|
+
* ```typescript
|
|
459
|
+
* const sandbox = await DaytonaSandbox.create({
|
|
460
|
+
* language: "typescript",
|
|
461
|
+
* cpu: 2,
|
|
462
|
+
* memory: 4,
|
|
463
|
+
* });
|
|
464
|
+
* ```
|
|
465
|
+
*/
|
|
466
|
+
static create(options?: DaytonaSandboxOptions): Promise<DaytonaSandbox>;
|
|
467
|
+
/**
|
|
468
|
+
* Connect to an existing sandbox by ID.
|
|
469
|
+
*
|
|
470
|
+
* This allows you to resume working with a sandbox that was created
|
|
471
|
+
* earlier or that is still running.
|
|
472
|
+
*
|
|
473
|
+
* @param sandboxId - The ID of the sandbox to connect to
|
|
474
|
+
* @param options - Optional auth configuration (for API key)
|
|
475
|
+
* @returns A connected sandbox instance
|
|
476
|
+
*
|
|
477
|
+
* @example
|
|
478
|
+
* ```typescript
|
|
479
|
+
* // Resume a sandbox from a stored ID
|
|
480
|
+
* const sandbox = await DaytonaSandbox.connect("sandbox-abc123");
|
|
481
|
+
* const result = await sandbox.execute("ls -la");
|
|
482
|
+
* ```
|
|
483
|
+
*/
|
|
484
|
+
static connect(sandboxId: string, options?: Pick<DaytonaSandboxOptions, "auth" | "target" | "timeout">): Promise<DaytonaSandbox>;
|
|
485
|
+
}
|
|
486
|
+
/**
|
|
487
|
+
* Async factory function type for creating Daytona Sandbox instances.
|
|
488
|
+
*
|
|
489
|
+
* This is similar to BackendFactory but supports async creation,
|
|
490
|
+
* which is required for Daytona Sandbox since initialization is async.
|
|
491
|
+
*/
|
|
492
|
+
type AsyncDaytonaSandboxFactory = () => Promise<DaytonaSandbox>;
|
|
493
|
+
/**
|
|
494
|
+
* Create an async factory function that creates a new Daytona Sandbox per invocation.
|
|
495
|
+
*
|
|
496
|
+
* Each call to the factory will create and initialize a new sandbox.
|
|
497
|
+
* This is useful when you want fresh, isolated environments for each
|
|
498
|
+
* agent invocation.
|
|
499
|
+
*
|
|
500
|
+
* **Important**: This returns an async factory. For use with middleware that
|
|
501
|
+
* requires synchronous BackendFactory, use `createDaytonaSandboxFactoryFromSandbox()`
|
|
502
|
+
* with a pre-created sandbox instead.
|
|
503
|
+
*
|
|
504
|
+
* @param options - Optional configuration for sandbox creation
|
|
505
|
+
* @returns An async factory function that creates new sandboxes
|
|
506
|
+
*
|
|
507
|
+
* @example
|
|
508
|
+
* ```typescript
|
|
509
|
+
* import { DaytonaSandbox, createDaytonaSandboxFactory } from "@langchain/daytona";
|
|
510
|
+
*
|
|
511
|
+
* // Create a factory for new sandboxes
|
|
512
|
+
* const factory = createDaytonaSandboxFactory({ language: "typescript" });
|
|
513
|
+
*
|
|
514
|
+
* // Each call creates a new sandbox
|
|
515
|
+
* const sandbox1 = await factory();
|
|
516
|
+
* const sandbox2 = await factory();
|
|
517
|
+
*
|
|
518
|
+
* try {
|
|
519
|
+
* // Use sandboxes...
|
|
520
|
+
* } finally {
|
|
521
|
+
* await sandbox1.close();
|
|
522
|
+
* await sandbox2.close();
|
|
523
|
+
* }
|
|
524
|
+
* ```
|
|
525
|
+
*/
|
|
526
|
+
declare function createDaytonaSandboxFactory(options?: DaytonaSandboxOptions): AsyncDaytonaSandboxFactory;
|
|
527
|
+
/**
|
|
528
|
+
* Create a backend factory that reuses an existing Daytona Sandbox.
|
|
529
|
+
*
|
|
530
|
+
* This allows multiple agent invocations to share the same sandbox,
|
|
531
|
+
* avoiding the startup overhead of creating new sandboxes.
|
|
532
|
+
*
|
|
533
|
+
* Important: You are responsible for managing the sandbox lifecycle
|
|
534
|
+
* (calling `close()` when done).
|
|
535
|
+
*
|
|
536
|
+
* @param sandbox - An existing DaytonaSandbox instance (must be initialized)
|
|
537
|
+
* @returns A BackendFactory that returns the provided sandbox
|
|
538
|
+
*
|
|
539
|
+
* @example
|
|
540
|
+
* ```typescript
|
|
541
|
+
* import { createDeepAgent, createFilesystemMiddleware } from "deepagents";
|
|
542
|
+
* import { DaytonaSandbox, createDaytonaSandboxFactoryFromSandbox } from "@langchain/daytona";
|
|
543
|
+
*
|
|
544
|
+
* // Create and initialize a sandbox
|
|
545
|
+
* const sandbox = await DaytonaSandbox.create({ language: "typescript" });
|
|
546
|
+
*
|
|
547
|
+
* try {
|
|
548
|
+
* const agent = createDeepAgent({
|
|
549
|
+
* model: new ChatAnthropic({ model: "claude-sonnet-4-20250514" }),
|
|
550
|
+
* systemPrompt: "You are a coding assistant.",
|
|
551
|
+
* middlewares: [
|
|
552
|
+
* createFilesystemMiddleware({
|
|
553
|
+
* backend: createDaytonaSandboxFactoryFromSandbox(sandbox),
|
|
554
|
+
* }),
|
|
555
|
+
* ],
|
|
556
|
+
* });
|
|
557
|
+
*
|
|
558
|
+
* await agent.invoke({ messages: [...] });
|
|
559
|
+
* } finally {
|
|
560
|
+
* await sandbox.close();
|
|
561
|
+
* }
|
|
562
|
+
* ```
|
|
563
|
+
*/
|
|
564
|
+
declare function createDaytonaSandboxFactoryFromSandbox(sandbox: DaytonaSandbox): BackendFactory;
|
|
565
|
+
//#endregion
|
|
566
|
+
//#region src/auth.d.ts
|
|
567
|
+
/**
|
|
568
|
+
* Authentication credentials for Daytona API.
|
|
569
|
+
*/
|
|
570
|
+
interface DaytonaCredentials {
|
|
571
|
+
/** Daytona API key */
|
|
572
|
+
apiKey: string;
|
|
573
|
+
/** Daytona API URL */
|
|
574
|
+
apiUrl: string;
|
|
575
|
+
/** Target region */
|
|
576
|
+
target?: string;
|
|
577
|
+
}
|
|
578
|
+
/**
|
|
579
|
+
* Get the API key for Daytona API.
|
|
580
|
+
*
|
|
581
|
+
* Authentication is resolved in the following priority order:
|
|
582
|
+
*
|
|
583
|
+
* 1. **Explicit API key**: If `options.apiKey` is provided, it is used directly.
|
|
584
|
+
* 2. **DAYTONA_API_KEY**: Environment variable for Daytona API key.
|
|
585
|
+
*
|
|
586
|
+
* If no API key is found, an error is thrown with setup instructions.
|
|
587
|
+
*
|
|
588
|
+
* ## Environment Variable Setup
|
|
589
|
+
*
|
|
590
|
+
* ```bash
|
|
591
|
+
* # Get your API key from https://app.daytona.io
|
|
592
|
+
* export DAYTONA_API_KEY=your_api_key_here
|
|
593
|
+
* ```
|
|
594
|
+
*
|
|
595
|
+
* @param options - Optional authentication configuration from DaytonaSandboxOptions
|
|
596
|
+
* @returns The API key string
|
|
597
|
+
* @throws {Error} If no API key is available
|
|
598
|
+
*
|
|
599
|
+
* @example
|
|
600
|
+
* ```typescript
|
|
601
|
+
* // With explicit API key
|
|
602
|
+
* const apiKey = getAuthApiKey({ apiKey: "my-api-key" });
|
|
603
|
+
*
|
|
604
|
+
* // Using environment variables (auto-detected)
|
|
605
|
+
* const apiKey = getAuthApiKey();
|
|
606
|
+
*
|
|
607
|
+
* // From DaytonaSandboxOptions
|
|
608
|
+
* const options: DaytonaSandboxOptions = {
|
|
609
|
+
* auth: { apiKey: "my-api-key" }
|
|
610
|
+
* };
|
|
611
|
+
* const apiKey = getAuthApiKey(options.auth);
|
|
612
|
+
* ```
|
|
613
|
+
*/
|
|
614
|
+
declare function getAuthApiKey(options?: DaytonaSandboxOptions["auth"]): string;
|
|
615
|
+
/**
|
|
616
|
+
* Get the API URL for Daytona API.
|
|
617
|
+
*
|
|
618
|
+
* URL is resolved in the following priority order:
|
|
619
|
+
*
|
|
620
|
+
* 1. **Explicit API URL**: If `options.apiUrl` is provided, it is used directly.
|
|
621
|
+
* 2. **DAYTONA_API_URL**: Environment variable for Daytona API URL.
|
|
622
|
+
* 3. **Default**: Uses the default Daytona API URL.
|
|
623
|
+
*
|
|
624
|
+
* @param options - Optional authentication configuration from DaytonaSandboxOptions
|
|
625
|
+
* @returns The API URL string
|
|
626
|
+
*/
|
|
627
|
+
declare function getAuthApiUrl(options?: DaytonaSandboxOptions["auth"]): string;
|
|
628
|
+
/**
|
|
629
|
+
* Get authentication credentials for Daytona API.
|
|
630
|
+
*
|
|
631
|
+
* This function returns the credentials needed for the Daytona SDK.
|
|
632
|
+
*
|
|
633
|
+
* @param options - Optional authentication configuration from DaytonaSandboxOptions
|
|
634
|
+
* @param target - Optional target region
|
|
635
|
+
* @returns Complete authentication credentials
|
|
636
|
+
* @throws {Error} If no API key is available
|
|
637
|
+
*/
|
|
638
|
+
declare function getAuthCredentials(options?: DaytonaSandboxOptions["auth"], target?: string): DaytonaCredentials;
|
|
639
|
+
//#endregion
|
|
640
|
+
export { type AsyncDaytonaSandboxFactory, type DaytonaCredentials, DaytonaSandbox, DaytonaSandboxError, type DaytonaSandboxErrorCode, type DaytonaSandboxOptions, type DaytonaSandboxTarget, createDaytonaSandboxFactory, createDaytonaSandboxFactoryFromSandbox, getAuthApiKey, getAuthApiUrl, getAuthCredentials };
|
|
641
|
+
//# sourceMappingURL=index.d.cts.map
|