-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdevboxes.ts
More file actions
1570 lines (1383 loc) · 47.3 KB
/
devboxes.ts
File metadata and controls
1570 lines (1383 loc) · 47.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
import { APIResource } from '../../resource';
import { isRequestOptions } from '../../core';
import * as Core from '../../core';
import * as Shared from '../shared';
import * as BrowsersAPI from './browsers';
import { BrowserCreateParams, BrowserView, Browsers } from './browsers';
import * as ComputersAPI from './computers';
import {
ComputerCreateParams,
ComputerKeyboardInteractionParams,
ComputerKeyboardInteractionResponse,
ComputerMouseInteractionParams,
ComputerMouseInteractionResponse,
ComputerScreenInteractionParams,
ComputerScreenInteractionResponse,
ComputerView,
Computers,
} from './computers';
import * as DiskSnapshotsAPI from './disk-snapshots';
import {
DevboxSnapshotAsyncStatusView,
DiskSnapshotDeleteResponse,
DiskSnapshotListParams,
DiskSnapshotUpdateParams,
DiskSnapshots,
} from './disk-snapshots';
import * as ExecutionsAPI from './executions';
import {
ExecutionExecuteAsyncParams,
ExecutionExecuteSyncParams,
ExecutionKillParams,
ExecutionRetrieveParams,
ExecutionSendStdInParams,
ExecutionStreamStderrUpdatesParams,
ExecutionStreamStdoutUpdatesParams,
ExecutionUpdateChunk,
Executions,
} from './executions';
import * as LogsAPI from './logs';
import { DevboxLogsListView, LogListParams, Logs } from './logs';
import {
DevboxesCursorIDPage,
type DevboxesCursorIDPageParams,
DiskSnapshotsCursorIDPage,
type DiskSnapshotsCursorIDPageParams,
} from '../../pagination';
import { type Response } from '../../_shims/index';
import {
longPollUntil,
LongPollRequestOptions,
resolveLongPollTimeoutMs,
} from '@runloop/api-client/lib/polling';
import { awaitDevboxState } from '@runloop/api-client/lib/devbox-state';
import { DevboxTools } from './tools';
import { uuidv7 } from 'uuidv7';
type DevboxStatus = DevboxView['status'];
const DEVBOX_BOOTING_STATES: DevboxStatus[] = ['provisioning', 'initializing'];
export class Devboxes extends APIResource {
diskSnapshots: DiskSnapshotsAPI.DiskSnapshots = new DiskSnapshotsAPI.DiskSnapshots(this._client);
browsers: BrowsersAPI.Browsers = new BrowsersAPI.Browsers(this._client);
computers: ComputersAPI.Computers = new ComputersAPI.Computers(this._client);
logs: LogsAPI.Logs = new LogsAPI.Logs(this._client);
executions: ExecutionsAPI.Executions = new ExecutionsAPI.Executions(this._client);
/**
* Create a Devbox and begin the boot process. The Devbox will initially launch in
* the 'provisioning' state while Runloop allocates the necessary infrastructure.
* It will transition to the 'initializing' state while the booted Devbox runs any
* Runloop or user defined set up scripts. Finally, the Devbox will transition to
* the 'running' state when it is ready for use.
*/
create(body?: DevboxCreateParams, options?: Core.RequestOptions): Core.APIPromise<DevboxView>;
create(options?: Core.RequestOptions): Core.APIPromise<DevboxView>;
create(
body: DevboxCreateParams | Core.RequestOptions = {},
options?: Core.RequestOptions,
): Core.APIPromise<DevboxView> {
if (isRequestOptions(body)) {
return this.create({}, body);
}
return this._client.post('/v1/devboxes', { body, ...options });
}
/**
* Get the latest details and status of a Devbox.
*/
retrieve(id: string, options?: Core.RequestOptions): Core.APIPromise<DevboxView> {
return this._client.get(`/v1/devboxes/${id}`, options);
}
/**
* Wait for a devbox to reach the running state.
* Long Polls the devbox status until it reaches running state.
*
* @param id - Devbox ID
* @param options - request options with optional long-poll configuration.
*/
async awaitRunning(id: string, options?: LongPollRequestOptions<DevboxView>): Promise<DevboxView> {
return awaitDevboxState<DevboxView>({
client: this._client,
devboxId: id,
targetState: 'running',
statesToCheck: ['running', 'failure', 'shutdown'],
transitionStates: DEVBOX_BOOTING_STATES,
timeoutMs: resolveLongPollTimeoutMs(options),
signal: options?.signal,
errorMessage: (devboxId, actualState) => `Devbox ${devboxId} is in non-running state ${actualState}`,
});
}
/**
* Wait for a devbox to reach the suspended state.
* Long Polls the devbox status until it reaches suspended state.
*
* @param id - Devbox ID
* @param options - request options with optional long-poll configuration.
*/
async awaitSuspended(id: string, options?: LongPollRequestOptions<DevboxView>): Promise<DevboxView> {
return awaitDevboxState<DevboxView>({
client: this._client,
devboxId: id,
targetState: 'suspended',
statesToCheck: ['suspended', 'failure', 'shutdown'],
transitionStates: ['suspending'],
timeoutMs: resolveLongPollTimeoutMs(options),
signal: options?.signal,
errorMessage: (devboxId, actualState) => `Devbox ${devboxId} is in non-suspended state ${actualState}`,
});
}
/**
* Create a devbox and wait for it to reach the running state.
* This is a convenience method that combines create() and awaitDevboxRunning().
*
* @param body - DevboxCreateParams
* @param options - request options with optional long-poll configuration.
*/
async createAndAwaitRunning(
body?: DevboxCreateParams,
options?: LongPollRequestOptions<DevboxView>,
): Promise<DevboxView> {
const { longPoll, polling, ...requestOptions } = options ?? {};
const devbox = await this.create(body, requestOptions);
return this.awaitRunning(devbox.id, { ...requestOptions, longPoll, polling });
}
/**
* Updates a devbox by doing a complete update the existing name,metadata fields.
* It does not patch partial values.
*/
update(id: string, body?: DevboxUpdateParams, options?: Core.RequestOptions): Core.APIPromise<DevboxView>;
update(id: string, options?: Core.RequestOptions): Core.APIPromise<DevboxView>;
update(
id: string,
body: DevboxUpdateParams | Core.RequestOptions = {},
options?: Core.RequestOptions,
): Core.APIPromise<DevboxView> {
if (isRequestOptions(body)) {
return this.update(id, {}, body);
}
return this._client.post(`/v1/devboxes/${id}`, { body, ...options });
}
/**
* List all Devboxes while optionally filtering by status.
*/
list(
query?: DevboxListParams,
options?: Core.RequestOptions,
): Core.PagePromise<DevboxViewsDevboxesCursorIDPage, DevboxView>;
list(options?: Core.RequestOptions): Core.PagePromise<DevboxViewsDevboxesCursorIDPage, DevboxView>;
list(
query: DevboxListParams | Core.RequestOptions = {},
options?: Core.RequestOptions,
): Core.PagePromise<DevboxViewsDevboxesCursorIDPage, DevboxView> {
if (isRequestOptions(query)) {
return this.list({}, query);
}
return this._client.getAPIList('/v1/devboxes', DevboxViewsDevboxesCursorIDPage, { query, ...options });
}
/**
* Create an SSH key for a Devbox to enable remote access.
*/
createSSHKey(id: string, options?: Core.RequestOptions): Core.APIPromise<DevboxCreateSSHKeyResponse> {
return this._client.post(`/v1/devboxes/${id}/create_ssh_key`, options);
}
/**
* Delete a previously taken disk snapshot of a Devbox.
*/
deleteDiskSnapshot(id: string, options?: Core.RequestOptions): Core.APIPromise<unknown> {
return this._client.post(`/v1/devboxes/disk_snapshots/${id}/delete`, options);
}
/**
* Download file contents of any type (binary, text, etc) from a specified path on
* the Devbox.
*/
downloadFile(
id: string,
body: DevboxDownloadFileParams,
options?: Core.RequestOptions,
): Core.APIPromise<Response> {
return this._client.post(`/v1/devboxes/${id}/download_file`, {
body,
timeout: this._client.timeout ?? 600000,
...options,
headers: { Accept: 'application/octet-stream', ...options?.headers },
__binaryResponse: true,
});
}
/**
* Enable a V2 tunnel for an existing running Devbox. Tunnels provide encrypted
* URL-based access to the Devbox without exposing internal IDs. The tunnel URL
* format is: https://{port}-{tunnel_key}.tunnel.runloop.ai
*
* Each Devbox can have one tunnel.
*/
enableTunnel(
id: string,
body?: DevboxEnableTunnelParams,
options?: Core.RequestOptions,
): Core.APIPromise<TunnelView>;
enableTunnel(id: string, options?: Core.RequestOptions): Core.APIPromise<TunnelView>;
enableTunnel(
id: string,
body: DevboxEnableTunnelParams | Core.RequestOptions = {},
options?: Core.RequestOptions,
): Core.APIPromise<TunnelView> {
if (isRequestOptions(body)) {
return this.enableTunnel(id, {}, body);
}
return this._client.post(`/v1/devboxes/${id}/enable_tunnel`, { body, ...options });
}
/**
* Execute a command with a known command ID on a devbox, optimistically waiting
* for it to complete within the specified timeout. If it completes in time, return
* the result. If not, return a status indicating the command is still running.
* Note: attach_stdin parameter is not supported; use execute_async for stdin
* support.
*/
execute(
id: string,
params: DevboxExecuteParams,
options?: Core.RequestOptions,
): Core.APIPromise<DevboxAsyncExecutionDetailView> {
const { last_n, ...body } = params;
return this._client.post(`/v1/devboxes/${id}/execute`, {
body: {
...body,
command_id: body.command_id || uuidv7(),
},
query: { last_n },
timeout: this._client.timeout ?? 600000,
...options,
});
}
/**
* Execute a command and wait for it to complete with optimal latency for long running commands that can't rely on just polling.
*
* @param devboxId - Devbox ID
* @param params - Execution parameters.
* @param options - request options with optional long-poll configuration.
*/
async executeAndAwaitCompletion(
devboxId: string,
params: Omit<DevboxExecuteParams, 'command_id'>,
options?: LongPollRequestOptions<DevboxAsyncExecutionDetailView>,
): Promise<DevboxAsyncExecutionDetailView> {
const { longPoll, polling, ...requestOptions } = options ?? {};
const effectiveTimeoutMs = resolveLongPollTimeoutMs(options);
const commandId = uuidv7();
const execution = await this.execute(
devboxId,
{ ...params, command_id: commandId },
{ ...{ timeout: requestOptions?.timeout ?? effectiveTimeoutMs ?? 600000 }, ...requestOptions },
);
if (execution.status === 'completed') {
return execution;
}
const waitForCommandBody: DevboxWaitForCommandParams = {
statuses: ['completed'],
};
if (params.last_n) {
waitForCommandBody.last_n = params.last_n;
}
const finalResult = await longPollUntil(
(signal) =>
this.waitForCommand(devboxId, execution.execution_id, waitForCommandBody, {
signal,
// Per-request HTTP timeout must exceed the server's max long-poll hold (25s)
// so the server's 408 always arrives before the client aborts the connection.
// The longPollUntil AbortSignal enforces the caller's actual deadline.
timeout: 600000,
// Disable base-client retries so 408s surface immediately to longPollUntil
// (the server's wait_for_status endpoint sets x-should-retry: true for executions).
maxRetries: 0,
}),
{
timeoutMs: effectiveTimeoutMs,
shouldStop: (result) => result.status === 'completed',
signal: requestOptions.signal,
},
);
return finalResult;
}
/**
* Execute the given command in the Devbox shell asynchronously and returns the
* execution that can be used to track the command's progress.
*/
executeAsync(
id: string,
body: DevboxExecuteAsyncParams,
options?: Core.RequestOptions,
): Core.APIPromise<DevboxAsyncExecutionDetailView> {
return this._client.post(`/v1/devboxes/${id}/execute_async`, { body, ...options });
}
/**
* Execute a bash command in the Devbox shell, await the command completion and
* return the output. Note: attach_stdin parameter is not supported for synchronous
* execution.
*
* @deprecated Use execute, executeAsync, or executeAndAwaitCompletion instead.
*/
executeSync(
id: string,
body: DevboxExecuteSyncParams,
options?: Core.RequestOptions,
): Core.APIPromise<DevboxExecutionDetailView> {
return this._client.post(`/v1/devboxes/${id}/execute_sync`, {
body,
timeout: this._client.timeout ?? 600000,
...options,
});
}
/**
* Send a 'Keep Alive' signal to a running Devbox that is configured to shutdown on
* idle so the idle time resets.
*/
keepAlive(id: string, options?: Core.RequestOptions): Core.APIPromise<DevboxKeepAliveResponse> {
return this._client.post(`/v1/devboxes/${id}/keep_alive`, options);
}
/**
* List all snapshots of a Devbox while optionally filtering by Devbox ID, source
* Blueprint ID, and metadata.
*/
listDiskSnapshots(
query?: DevboxListDiskSnapshotsParams,
options?: Core.RequestOptions,
): Core.PagePromise<DevboxSnapshotViewsDiskSnapshotsCursorIDPage, DevboxSnapshotView>;
listDiskSnapshots(
options?: Core.RequestOptions,
): Core.PagePromise<DevboxSnapshotViewsDiskSnapshotsCursorIDPage, DevboxSnapshotView>;
listDiskSnapshots(
query: DevboxListDiskSnapshotsParams | Core.RequestOptions = {},
options?: Core.RequestOptions,
): Core.PagePromise<DevboxSnapshotViewsDiskSnapshotsCursorIDPage, DevboxSnapshotView> {
if (isRequestOptions(query)) {
return this.listDiskSnapshots({}, query);
}
return this._client.getAPIList(
'/v1/devboxes/disk_snapshots',
DevboxSnapshotViewsDiskSnapshotsCursorIDPage,
{ query, ...options },
);
}
/**
* Read file contents from a file on a Devbox as a UTF-8. Note 'downloadFile'
* should be used for large files (greater than 100MB). Returns the file contents
* as a UTF-8 string.
*/
readFileContents(
id: string,
body: DevboxReadFileContentsParams,
options?: Core.RequestOptions,
): Core.APIPromise<string> {
return this._client.post(`/v1/devboxes/${id}/read_file_contents`, {
body,
timeout: this._client.timeout ?? 600000,
...options,
headers: { Accept: 'text/plain', ...options?.headers },
});
}
/**
* @deprecated Only works with legacy tunnels created via {@link createTunnel}.
* V2 tunnels (from {@link enableTunnel}) remain active until devbox shutdown and cannot be removed.
*
* Remove a legacy tunnel from the devbox.
*/
removeTunnel(
id: string,
body: DevboxRemoveTunnelParams,
options?: Core.RequestOptions,
): Core.APIPromise<unknown> {
return this._client.post(`/v1/devboxes/${id}/remove_tunnel`, { body, ...options });
}
/**
* Resume a suspended Devbox with the disk state captured as suspend time. Note
* that any previously running processes or daemons will need to be restarted using
* the Devbox shell tools.
*/
resume(id: string, options?: Core.RequestOptions): Core.APIPromise<DevboxView> {
return this._client.post(`/v1/devboxes/${id}/resume`, options);
}
/**
* Get resource usage metrics for a specific Devbox. Returns CPU, memory, and disk
* consumption calculated from the Devbox's lifecycle, excluding any suspended
* periods for CPU and memory. Disk usage includes the full elapsed time since
* storage is consumed even when suspended.
*/
retrieveResourceUsage(id: string, options?: Core.RequestOptions): Core.APIPromise<DevboxResourceUsageView> {
return this._client.get(`/v1/devboxes/${id}/usage`, options);
}
/**
* Shutdown a running Devbox. This will permanently stop the Devbox. If you want to
* save the state of the Devbox, you should take a snapshot before shutting down or
* should suspend the Devbox instead of shutting down. If the Devbox has any
* in-progress snapshots, the shutdown will be rejected with a 409 Conflict unless
* force=true is specified.
*/
shutdown(
id: string,
params?: DevboxShutdownParams,
options?: Core.RequestOptions,
): Core.APIPromise<DevboxView>;
shutdown(id: string, options?: Core.RequestOptions): Core.APIPromise<DevboxView>;
shutdown(
id: string,
params: DevboxShutdownParams | Core.RequestOptions = {},
options?: Core.RequestOptions,
): Core.APIPromise<DevboxView> {
if (isRequestOptions(params)) {
return this.shutdown(id, {}, params);
}
const { force } = params;
return this._client.post(`/v1/devboxes/${id}/shutdown`, { query: { force }, ...options });
}
/**
* Create a disk snapshot of a devbox with the specified name and metadata to
* enable launching future Devboxes with the same disk state.
*/
snapshotDisk(
id: string,
body?: DevboxSnapshotDiskParams,
options?: Core.RequestOptions,
): Core.APIPromise<DevboxSnapshotView>;
snapshotDisk(id: string, options?: Core.RequestOptions): Core.APIPromise<DevboxSnapshotView>;
snapshotDisk(
id: string,
body: DevboxSnapshotDiskParams | Core.RequestOptions = {},
options?: Core.RequestOptions,
): Core.APIPromise<DevboxSnapshotView> {
if (isRequestOptions(body)) {
return this.snapshotDisk(id, {}, body);
}
return this._client.post(`/v1/devboxes/${id}/snapshot_disk`, {
body,
timeout: this._client.timeout ?? 600000,
...options,
});
}
/**
* Start an asynchronous disk snapshot of a devbox with the specified name and
* metadata. The snapshot operation will continue in the background and can be
* monitored using the query endpoint.
*/
snapshotDiskAsync(
id: string,
body?: DevboxSnapshotDiskAsyncParams,
options?: Core.RequestOptions,
): Core.APIPromise<DevboxSnapshotView>;
snapshotDiskAsync(id: string, options?: Core.RequestOptions): Core.APIPromise<DevboxSnapshotView>;
snapshotDiskAsync(
id: string,
body: DevboxSnapshotDiskAsyncParams | Core.RequestOptions = {},
options?: Core.RequestOptions,
): Core.APIPromise<DevboxSnapshotView> {
if (isRequestOptions(body)) {
return this.snapshotDiskAsync(id, {}, body);
}
return this._client.post(`/v1/devboxes/${id}/snapshot_disk_async`, { body, ...options });
}
/**
* Suspend a running Devbox and create a disk snapshot to enable resuming the
* Devbox later with the same disk. Note this will not snapshot memory state such
* as running processes.
*/
suspend(id: string, options?: Core.RequestOptions): Core.APIPromise<DevboxView> {
return this._client.post(`/v1/devboxes/${id}/suspend`, options);
}
/**
* Upload file contents of any type (binary, text, etc) to a Devbox. Note this API
* is suitable for large files (larger than 100MB) and efficiently uploads files
* via multipart form data.
*/
uploadFile(
id: string,
body: DevboxUploadFileParams,
options?: Core.RequestOptions,
): Core.APIPromise<unknown> {
return this._client.post(
`/v1/devboxes/${id}/upload_file`,
Core.multipartFormRequestOptions({
body,
timeout: this._client.timeout ?? 600000,
...options,
}),
);
}
/**
* Polls the asynchronous execution's status until it reaches one of the desired
* statuses or times out. Max is 25 seconds.
*/
waitForCommand(
devboxId: string,
executionId: string,
params: DevboxWaitForCommandParams,
options?: Core.RequestOptions,
): Core.APIPromise<DevboxAsyncExecutionDetailView> {
const { last_n, ...body } = params;
return this._client.post(`/v1/devboxes/${devboxId}/executions/${executionId}/wait_for_status`, {
query: { last_n },
body,
...options,
});
}
/**
* Write UTF-8 string contents to a file at path on the Devbox. Note for large
* files (larger than 100MB), the upload_file endpoint must be used.
*/
writeFileContents(
id: string,
body: DevboxWriteFileContentsParams,
options?: Core.RequestOptions,
): Core.APIPromise<DevboxExecutionDetailView> {
return this._client.post(`/v1/devboxes/${id}/write_file_contents`, {
body,
timeout: this._client.timeout ?? 600000,
...options,
});
}
// Make an accessor for tools
get tools(): DevboxTools {
return new DevboxTools(this);
}
}
export class DevboxViewsDevboxesCursorIDPage extends DevboxesCursorIDPage<DevboxView> {}
export class DevboxSnapshotViewsDiskSnapshotsCursorIDPage extends DiskSnapshotsCursorIDPage<DevboxSnapshotView> {}
/**
* Details of an asynchronous command execution on a Devbox.
*
* @category Devbox Types
*/
export interface DevboxAsyncExecutionDetailView {
/**
* Devbox id where command was executed.
*/
devbox_id: string;
/**
* Ephemeral id of the execution in progress.
*/
execution_id: string;
/**
* Current status of the execution.
*/
status: 'queued' | 'running' | 'completed';
/**
* Exit code of command execution. This field will remain unset until the execution
* has completed.
*/
exit_status?: number | null;
/**
* Shell name.
*/
shell_name?: string | null;
/**
* Standard error generated by command. This field will remain unset until the
* execution has completed.
*/
stderr?: string | null;
/**
* Indicates whether the stderr was truncated due to size limits.
*/
stderr_truncated?: boolean | null;
/**
* Standard out generated by command. This field will remain unset until the
* execution has completed.
*/
stdout?: string | null;
/**
* Indicates whether the stdout was truncated due to size limits.
*/
stdout_truncated?: boolean | null;
}
export interface DevboxExecutionDetailView {
/**
* Devbox id where command was executed.
*/
devbox_id: string;
/**
* Exit status of command execution.
*/
exit_status: number;
/**
* Standard error generated by command.
*/
stderr: string;
/**
* Standard out generated by command.
*/
stdout: string;
/**
* Shell name.
*/
shell_name?: string | null;
}
export interface DevboxKillExecutionRequest {
/**
* Whether to kill the entire process group (default: false). If true, kills all
* processes in the same process group as the target process.
*/
kill_process_group?: boolean | null;
}
export interface DevboxListView {
/**
* List of devboxes matching filter.
*/
devboxes: Array<DevboxView>;
has_more: boolean;
remaining_count?: number | null;
total_count?: number | null;
}
export interface DevboxResourceUsageView {
/**
* The devbox ID.
*/
id: string;
/**
* Disk usage in GB-seconds (total_elapsed_seconds multiplied by disk size in GB).
* Disk is billed for elapsed time since storage is consumed even when suspended.
*/
disk_gb_seconds: number;
/**
* Memory usage in GB-seconds (total_active_seconds multiplied by memory in GB).
*/
memory_gb_seconds: number;
/**
* The devbox creation time in milliseconds since epoch.
*/
start_time_ms: number;
/**
* The current status of the devbox.
*/
status: string;
/**
* Total time in seconds the devbox was actively running (excludes time spent
* suspended).
*/
total_active_seconds: number;
/**
* Total elapsed time in seconds from devbox creation to now (or end time if
* terminated). Includes all time regardless of devbox state.
*/
total_elapsed_seconds: number;
/**
* vCPU usage in vCPU-seconds (total_active_seconds multiplied by the number of
* vCPUs).
*/
vcpu_seconds: number;
/**
* The devbox end time in milliseconds since epoch, or null if still running.
*/
end_time_ms?: number | null;
}
export interface DevboxSendStdInRequest {
/**
* Signal to send to std in of the running execution.
*/
signal?: 'EOF' | 'INTERRUPT' | null;
/**
* Text to send to std in of the running execution.
*/
text?: string | null;
}
export interface DevboxSendStdInResult {
/**
* Devbox id where command is executing.
*/
devbox_id: string;
/**
* Execution id that received the stdin.
*/
execution_id: string;
/**
* Whether the stdin was successfully sent.
*/
success: boolean;
}
export interface DevboxSnapshotListView {
has_more: boolean;
/**
* List of snapshots matching filter.
*/
snapshots: Array<DevboxSnapshotView>;
remaining_count?: number | null;
total_count?: number | null;
}
/**
* View of a Devbox disk snapshot.
*
* @category Snapshot Types
*/
export interface DevboxSnapshotView {
/**
* The unique identifier of the snapshot.
*/
id: string;
/**
* Creation time of the Snapshot (Unix timestamp milliseconds).
*/
create_time_ms: number;
/**
* User defined metadata associated with the snapshot.
*/
metadata: { [key: string]: string };
/**
* The source Devbox ID this snapshot was created from.
*/
source_devbox_id: string;
/**
* (Optional) The commit message of the snapshot (max 1000 characters).
*/
commit_message?: string | null;
/**
* (Optional) The custom name of the snapshot.
*/
name?: string | null;
/**
* (Optional) The size of the snapshot in bytes, relative to the base blueprint.
*/
size_bytes?: number | null;
/**
* (Optional) The source Blueprint ID this snapshot was created from.
*/
source_blueprint_id?: string | null;
}
/**
* A Devbox represents a virtual development environment. It is an isolated sandbox
* that can be given to agents and used to run arbitrary code such as AI generated
* code.
*
* @category Devbox Types
*/
export interface DevboxView {
/**
* The ID of the Devbox.
*/
id: string;
/**
* A list of capability groups this devbox has access to. This allows devboxes to
* be compatible with certain tools sets like computer usage APIs.
*/
capabilities: Array<'unknown' | 'computer_usage' | 'browser_usage' | 'docker_in_docker'>;
/**
* Creation time of the Devbox (Unix timestamp milliseconds).
*/
create_time_ms: number;
/**
* The time the Devbox finished execution (Unix timestamp milliseconds). Present if
* the Devbox is in a terminal state.
*/
end_time_ms: number | null;
/**
* The launch parameters used to create the Devbox.
*/
launch_parameters: Shared.LaunchParameters;
/**
* The user defined Devbox metadata.
*/
metadata: { [key: string]: string };
/**
* A list of state transitions in order with durations
*/
state_transitions: Array<DevboxView.StateTransition>;
/**
* The current status of the Devbox.
*/
status:
| 'provisioning'
| 'initializing'
| 'running'
| 'suspending'
| 'suspended'
| 'resuming'
| 'failure'
| 'shutdown';
/**
* The Blueprint ID used in creation of the Devbox, if the devbox was created from
* a Blueprint.
*/
blueprint_id?: string | null;
/**
* The failure reason if the Devbox failed, if the Devbox has a 'failure' status.
*/
failure_reason?: 'out_of_memory' | 'out_of_disk' | 'execution_failed' | null;
/**
* Gateway specifications configured for this devbox. Map key is the environment
* variable prefix (e.g., 'GWS_ANTHROPIC').
*/
gateway_specs?: { [key: string]: DevboxView.GatewaySpecs } | null;
/**
* The ID of the initiator that created the Devbox.
*/
initiator_id?: string | null;
/**
* The type of initiator that created the Devbox.
*/
initiator_type?: 'unknown' | 'api' | 'scenario' | 'scoring_validation';
/**
* [Beta] MCP specifications configured for this devbox. Map key is the environment
* variable name for the MCP token envelope. Each spec links an MCP config to a
* secret for MCP server access through the MCP hub.
*/
mcp_specs?: { [key: string]: DevboxView.McpSpecs } | null;
/**
* The name of the Devbox.
*/
name?: string | null;
/**
* The shutdown reason if the Devbox shutdown, if the Devbox has a 'shutdown'
* status.
*/
shutdown_reason?: 'api_shutdown' | 'keep_alive_timeout' | 'entrypoint_exit' | 'idle' | null;
/**
* The Snapshot ID used in creation of the Devbox, if the devbox was created from a
* Snapshot.
*/
snapshot_id?: string | null;
/**
* V2 tunnel information if a tunnel was created at launch time or via the
* createTunnel API.
*/
tunnel?: TunnelView | null;
}
export namespace DevboxView {
export interface StateTransition {
/**
* The status of the Devbox.
*
* provisioning: Runloop is allocating and booting the necessary infrastructure
* resources. initializing: Runloop defined boot scripts are running to enable the
* environment for interaction. running: The Devbox is ready for interaction.
* suspending: The Devbox disk is being snapshotted as part of suspension.
* suspended: The Devbox disk is saved and no more active compute is being used for
* the Devbox. resuming: The Devbox disk is being loaded as part of booting a
* suspended Devbox. failure: The Devbox failed as part of booting or running user
* requested actions. shutdown: The Devbox was successfully shutdown and no more
* active compute is being used.
*/
status?:
| 'provisioning'
| 'initializing'
| 'running'
| 'suspending'
| 'suspended'
| 'resuming'
| 'failure'
| 'shutdown';
/**
* The time the status change occurred
*/
transition_time_ms?: unknown;
}
export interface GatewaySpecs {
/**
* The ID of the gateway config (e.g., gwc_123abc).
*/
gateway_config_id: string;
/**
* The ID of the secret containing the credential.
*/
secret_id: string;
}
export interface McpSpecs {
/**
* The ID of the MCP config (e.g., mcp_123abc).
*/
mcp_config_id: string;
/**
* The ID of the secret containing the credential.
*/
secret_id: string;
}
}
/**
* A V2 tunnel provides secure HTTP access to services running on a Devbox. Tunnels
* allow external clients to reach web servers, APIs, or other HTTP services
* running inside a Devbox without requiring direct network access. Each tunnel is
* uniquely identified by an encrypted tunnel_key and can be configured for either
* open (public) or authenticated access. Usage: