@vercel/sandbox 0.0.21 → 0.0.23
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 +1 -1
- package/.turbo/turbo-typecheck.log +1 -1
- package/CHANGELOG.md +14 -0
- package/dist/api-client/api-client.d.ts +18 -1
- package/dist/api-client/api-client.js +22 -4
- package/dist/api-client/base-client.js +1 -0
- package/dist/api-client/validators.d.ts +87 -0
- package/dist/api-client/validators.js +4 -1
- package/dist/command.d.ts +26 -7
- package/dist/command.js +22 -10
- package/dist/sandbox.d.ts +60 -6
- package/dist/sandbox.js +57 -10
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
- package/src/api-client/api-client.ts +53 -6
- package/src/api-client/base-client.ts +1 -0
- package/src/api-client/validators.ts +4 -0
- package/src/command.ts +26 -10
- package/src/sandbox.test.ts +25 -0
- package/src/sandbox.ts +93 -11
- package/src/version.ts +1 -1
package/.turbo/turbo-build.log
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @vercel/sandbox
|
|
2
2
|
|
|
3
|
+
## 0.0.23
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Add `Sandbox.extendTimeout()` ([#148](https://github.com/vercel/sandbox-sdk/pull/148))
|
|
8
|
+
|
|
9
|
+
## 0.0.22
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- add AbortSignal support in public interface ([#137](https://github.com/vercel/sandbox-sdk/pull/137))
|
|
14
|
+
|
|
15
|
+
- add AbortSignal support to command.wait ([#136](https://github.com/vercel/sandbox-sdk/pull/136))
|
|
16
|
+
|
|
3
17
|
## 0.0.21
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BaseClient, type Parsed, type RequestParams } from "./base-client";
|
|
2
|
-
import { SandboxResponse, CommandResponse, CommandFinishedResponse, LogLine } from "./validators";
|
|
2
|
+
import { SandboxResponse, CommandResponse, CommandFinishedResponse, LogLine, ExtendTimeoutResponse } from "./validators";
|
|
3
3
|
import { FileWriter } from "./file-writer";
|
|
4
4
|
import { z } from "zod";
|
|
5
5
|
import { WithPrivate } from "../utils/types";
|
|
@@ -15,6 +15,7 @@ export declare class APIClient extends BaseClient {
|
|
|
15
15
|
protected request(path: string, params?: RequestParams): Promise<Response>;
|
|
16
16
|
getSandbox(params: {
|
|
17
17
|
sandboxId: string;
|
|
18
|
+
signal?: AbortSignal;
|
|
18
19
|
}): Promise<Parsed<{
|
|
19
20
|
sandbox: {
|
|
20
21
|
region: string;
|
|
@@ -58,6 +59,7 @@ export declare class APIClient extends BaseClient {
|
|
|
58
59
|
vcpus: number;
|
|
59
60
|
};
|
|
60
61
|
runtime?: "node22" | "python3.13" | (string & {});
|
|
62
|
+
signal?: AbortSignal;
|
|
61
63
|
}>): Promise<Parsed<{
|
|
62
64
|
sandbox: {
|
|
63
65
|
region: string;
|
|
@@ -89,6 +91,7 @@ export declare class APIClient extends BaseClient {
|
|
|
89
91
|
args: string[];
|
|
90
92
|
env: Record<string, string>;
|
|
91
93
|
sudo: boolean;
|
|
94
|
+
signal?: AbortSignal;
|
|
92
95
|
}): Promise<Parsed<{
|
|
93
96
|
command: {
|
|
94
97
|
name: string;
|
|
@@ -104,20 +107,24 @@ export declare class APIClient extends BaseClient {
|
|
|
104
107
|
sandboxId: string;
|
|
105
108
|
cmdId: string;
|
|
106
109
|
wait: true;
|
|
110
|
+
signal?: AbortSignal;
|
|
107
111
|
}): Promise<Parsed<z.infer<typeof CommandFinishedResponse>>>;
|
|
108
112
|
getCommand(params: {
|
|
109
113
|
sandboxId: string;
|
|
110
114
|
cmdId: string;
|
|
111
115
|
wait?: boolean;
|
|
116
|
+
signal?: AbortSignal;
|
|
112
117
|
}): Promise<Parsed<z.infer<typeof CommandResponse>>>;
|
|
113
118
|
mkDir(params: {
|
|
114
119
|
sandboxId: string;
|
|
115
120
|
path: string;
|
|
116
121
|
cwd?: string;
|
|
122
|
+
signal?: AbortSignal;
|
|
117
123
|
}): Promise<Parsed<{}>>;
|
|
118
124
|
getFileWriter(params: {
|
|
119
125
|
sandboxId: string;
|
|
120
126
|
extractDir: string;
|
|
127
|
+
signal?: AbortSignal;
|
|
121
128
|
}): {
|
|
122
129
|
response: Promise<Response>;
|
|
123
130
|
writer: FileWriter;
|
|
@@ -143,6 +150,7 @@ export declare class APIClient extends BaseClient {
|
|
|
143
150
|
* @example 1540095775951
|
|
144
151
|
*/
|
|
145
152
|
until?: number | Date;
|
|
153
|
+
signal?: AbortSignal;
|
|
146
154
|
}): Promise<Parsed<{
|
|
147
155
|
sandboxes: {
|
|
148
156
|
region: string;
|
|
@@ -175,16 +183,19 @@ export declare class APIClient extends BaseClient {
|
|
|
175
183
|
content: Buffer;
|
|
176
184
|
}[];
|
|
177
185
|
extractDir: string;
|
|
186
|
+
signal?: AbortSignal;
|
|
178
187
|
}): Promise<void>;
|
|
179
188
|
readFile(params: {
|
|
180
189
|
sandboxId: string;
|
|
181
190
|
path: string;
|
|
182
191
|
cwd?: string;
|
|
192
|
+
signal?: AbortSignal;
|
|
183
193
|
}): Promise<NodeJS.ReadableStream | null>;
|
|
184
194
|
killCommand(params: {
|
|
185
195
|
sandboxId: string;
|
|
186
196
|
commandId: string;
|
|
187
197
|
signal: number;
|
|
198
|
+
abortSignal?: AbortSignal;
|
|
188
199
|
}): Promise<Parsed<{
|
|
189
200
|
command: {
|
|
190
201
|
name: string;
|
|
@@ -205,5 +216,11 @@ export declare class APIClient extends BaseClient {
|
|
|
205
216
|
};
|
|
206
217
|
stopSandbox(params: {
|
|
207
218
|
sandboxId: string;
|
|
219
|
+
signal?: AbortSignal;
|
|
208
220
|
}): Promise<Parsed<z.infer<typeof SandboxResponse>>>;
|
|
221
|
+
extendTimeout(params: {
|
|
222
|
+
sandboxId: string;
|
|
223
|
+
duration: number;
|
|
224
|
+
signal?: AbortSignal;
|
|
225
|
+
}): Promise<Parsed<z.infer<typeof ExtendTimeoutResponse>>>;
|
|
209
226
|
}
|
|
@@ -53,7 +53,9 @@ class APIClient extends base_client_1.BaseClient {
|
|
|
53
53
|
});
|
|
54
54
|
}
|
|
55
55
|
async getSandbox(params) {
|
|
56
|
-
return (0, base_client_1.parseOrThrow)(validators_1.SandboxAndRoutesResponse, await this.request(`/v1/sandboxes/${params.sandboxId}
|
|
56
|
+
return (0, base_client_1.parseOrThrow)(validators_1.SandboxAndRoutesResponse, await this.request(`/v1/sandboxes/${params.sandboxId}`, {
|
|
57
|
+
signal: params.signal,
|
|
58
|
+
}));
|
|
57
59
|
}
|
|
58
60
|
async createSandbox(params) {
|
|
59
61
|
const privateParams = (0, types_1.getPrivateParams)(params);
|
|
@@ -68,6 +70,7 @@ class APIClient extends base_client_1.BaseClient {
|
|
|
68
70
|
runtime: params.runtime,
|
|
69
71
|
...privateParams,
|
|
70
72
|
}),
|
|
73
|
+
signal: params.signal,
|
|
71
74
|
}));
|
|
72
75
|
}
|
|
73
76
|
async runCommand(params) {
|
|
@@ -80,17 +83,19 @@ class APIClient extends base_client_1.BaseClient {
|
|
|
80
83
|
env: params.env,
|
|
81
84
|
sudo: params.sudo,
|
|
82
85
|
}),
|
|
86
|
+
signal: params.signal,
|
|
83
87
|
}));
|
|
84
88
|
}
|
|
85
89
|
async getCommand(params) {
|
|
86
90
|
return params.wait
|
|
87
|
-
? (0, base_client_1.parseOrThrow)(validators_1.CommandFinishedResponse, await this.request(`/v1/sandboxes/${params.sandboxId}/cmd/${params.cmdId}`, { query: { wait: "true" } }))
|
|
88
|
-
: (0, base_client_1.parseOrThrow)(validators_1.CommandResponse, await this.request(`/v1/sandboxes/${params.sandboxId}/cmd/${params.cmdId}
|
|
91
|
+
? (0, base_client_1.parseOrThrow)(validators_1.CommandFinishedResponse, await this.request(`/v1/sandboxes/${params.sandboxId}/cmd/${params.cmdId}`, { signal: params.signal, query: { wait: "true" } }))
|
|
92
|
+
: (0, base_client_1.parseOrThrow)(validators_1.CommandResponse, await this.request(`/v1/sandboxes/${params.sandboxId}/cmd/${params.cmdId}`, { signal: params.signal }));
|
|
89
93
|
}
|
|
90
94
|
async mkDir(params) {
|
|
91
95
|
return (0, base_client_1.parseOrThrow)(validators_1.EmptyResponse, await this.request(`/v1/sandboxes/${params.sandboxId}/fs/mkdir`, {
|
|
92
96
|
method: "POST",
|
|
93
97
|
body: JSON.stringify({ path: params.path, cwd: params.cwd }),
|
|
98
|
+
signal: params.signal,
|
|
94
99
|
}));
|
|
95
100
|
}
|
|
96
101
|
getFileWriter(params) {
|
|
@@ -104,6 +109,7 @@ class APIClient extends base_client_1.BaseClient {
|
|
|
104
109
|
"x-cwd": params.extractDir,
|
|
105
110
|
},
|
|
106
111
|
body: await (0, consume_readable_1.consumeReadable)(writer.readable),
|
|
112
|
+
signal: params.signal,
|
|
107
113
|
});
|
|
108
114
|
})(),
|
|
109
115
|
writer,
|
|
@@ -122,12 +128,14 @@ class APIClient extends base_client_1.BaseClient {
|
|
|
122
128
|
: params.until?.getTime(),
|
|
123
129
|
},
|
|
124
130
|
method: "GET",
|
|
131
|
+
signal: params.signal,
|
|
125
132
|
}));
|
|
126
133
|
}
|
|
127
134
|
async writeFiles(params) {
|
|
128
135
|
const { writer, response } = this.getFileWriter({
|
|
129
136
|
sandboxId: params.sandboxId,
|
|
130
137
|
extractDir: params.extractDir,
|
|
138
|
+
signal: params.signal,
|
|
131
139
|
});
|
|
132
140
|
for (const file of params.files) {
|
|
133
141
|
await writer.addFile({
|
|
@@ -146,6 +154,7 @@ class APIClient extends base_client_1.BaseClient {
|
|
|
146
154
|
const response = await this.request(`/v1/sandboxes/${params.sandboxId}/fs/read`, {
|
|
147
155
|
method: "POST",
|
|
148
156
|
body: JSON.stringify({ path: params.path, cwd: params.cwd }),
|
|
157
|
+
signal: params.signal,
|
|
149
158
|
});
|
|
150
159
|
if (response.status === 404) {
|
|
151
160
|
return null;
|
|
@@ -159,6 +168,7 @@ class APIClient extends base_client_1.BaseClient {
|
|
|
159
168
|
return (0, base_client_1.parseOrThrow)(validators_1.CommandResponse, await this.request(`/v1/sandboxes/${params.sandboxId}/${params.commandId}/kill`, {
|
|
160
169
|
method: "POST",
|
|
161
170
|
body: JSON.stringify({ signal: params.signal }),
|
|
171
|
+
signal: params.abortSignal,
|
|
162
172
|
}));
|
|
163
173
|
}
|
|
164
174
|
getLogs(params) {
|
|
@@ -200,7 +210,15 @@ class APIClient extends base_client_1.BaseClient {
|
|
|
200
210
|
}
|
|
201
211
|
async stopSandbox(params) {
|
|
202
212
|
const url = `/v1/sandboxes/${params.sandboxId}/stop`;
|
|
203
|
-
return (0, base_client_1.parseOrThrow)(validators_1.SandboxResponse, await this.request(url, { method: "POST" }));
|
|
213
|
+
return (0, base_client_1.parseOrThrow)(validators_1.SandboxResponse, await this.request(url, { method: "POST", signal: params.signal }));
|
|
214
|
+
}
|
|
215
|
+
async extendTimeout(params) {
|
|
216
|
+
const url = `/v1/sandboxes/${params.sandboxId}/extend-timeout`;
|
|
217
|
+
return (0, base_client_1.parseOrThrow)(validators_1.ExtendTimeoutResponse, await this.request(url, {
|
|
218
|
+
method: "POST",
|
|
219
|
+
body: JSON.stringify({ duration: params.duration }),
|
|
220
|
+
signal: params.signal,
|
|
221
|
+
}));
|
|
204
222
|
}
|
|
205
223
|
}
|
|
206
224
|
exports.APIClient = APIClient;
|
|
@@ -540,3 +540,90 @@ export declare const SandboxesResponse: z.ZodObject<{
|
|
|
540
540
|
prev: number | null;
|
|
541
541
|
};
|
|
542
542
|
}>;
|
|
543
|
+
export declare const ExtendTimeoutResponse: z.ZodObject<{
|
|
544
|
+
sandbox: z.ZodObject<{
|
|
545
|
+
id: z.ZodString;
|
|
546
|
+
memory: z.ZodNumber;
|
|
547
|
+
vcpus: z.ZodNumber;
|
|
548
|
+
region: z.ZodString;
|
|
549
|
+
runtime: z.ZodString;
|
|
550
|
+
timeout: z.ZodNumber;
|
|
551
|
+
status: z.ZodEnum<["pending", "running", "stopping", "stopped", "failed"]>;
|
|
552
|
+
requestedAt: z.ZodNumber;
|
|
553
|
+
startedAt: z.ZodOptional<z.ZodNumber>;
|
|
554
|
+
requestedStopAt: z.ZodOptional<z.ZodNumber>;
|
|
555
|
+
stoppedAt: z.ZodOptional<z.ZodNumber>;
|
|
556
|
+
duration: z.ZodOptional<z.ZodNumber>;
|
|
557
|
+
createdAt: z.ZodNumber;
|
|
558
|
+
cwd: z.ZodString;
|
|
559
|
+
updatedAt: z.ZodNumber;
|
|
560
|
+
}, "strip", z.ZodTypeAny, {
|
|
561
|
+
region: string;
|
|
562
|
+
status: "pending" | "running" | "stopping" | "stopped" | "failed";
|
|
563
|
+
timeout: number;
|
|
564
|
+
cwd: string;
|
|
565
|
+
id: string;
|
|
566
|
+
memory: number;
|
|
567
|
+
vcpus: number;
|
|
568
|
+
runtime: string;
|
|
569
|
+
requestedAt: number;
|
|
570
|
+
createdAt: number;
|
|
571
|
+
updatedAt: number;
|
|
572
|
+
duration?: number | undefined;
|
|
573
|
+
startedAt?: number | undefined;
|
|
574
|
+
requestedStopAt?: number | undefined;
|
|
575
|
+
stoppedAt?: number | undefined;
|
|
576
|
+
}, {
|
|
577
|
+
region: string;
|
|
578
|
+
status: "pending" | "running" | "stopping" | "stopped" | "failed";
|
|
579
|
+
timeout: number;
|
|
580
|
+
cwd: string;
|
|
581
|
+
id: string;
|
|
582
|
+
memory: number;
|
|
583
|
+
vcpus: number;
|
|
584
|
+
runtime: string;
|
|
585
|
+
requestedAt: number;
|
|
586
|
+
createdAt: number;
|
|
587
|
+
updatedAt: number;
|
|
588
|
+
duration?: number | undefined;
|
|
589
|
+
startedAt?: number | undefined;
|
|
590
|
+
requestedStopAt?: number | undefined;
|
|
591
|
+
stoppedAt?: number | undefined;
|
|
592
|
+
}>;
|
|
593
|
+
}, "strip", z.ZodTypeAny, {
|
|
594
|
+
sandbox: {
|
|
595
|
+
region: string;
|
|
596
|
+
status: "pending" | "running" | "stopping" | "stopped" | "failed";
|
|
597
|
+
timeout: number;
|
|
598
|
+
cwd: string;
|
|
599
|
+
id: string;
|
|
600
|
+
memory: number;
|
|
601
|
+
vcpus: number;
|
|
602
|
+
runtime: string;
|
|
603
|
+
requestedAt: number;
|
|
604
|
+
createdAt: number;
|
|
605
|
+
updatedAt: number;
|
|
606
|
+
duration?: number | undefined;
|
|
607
|
+
startedAt?: number | undefined;
|
|
608
|
+
requestedStopAt?: number | undefined;
|
|
609
|
+
stoppedAt?: number | undefined;
|
|
610
|
+
};
|
|
611
|
+
}, {
|
|
612
|
+
sandbox: {
|
|
613
|
+
region: string;
|
|
614
|
+
status: "pending" | "running" | "stopping" | "stopped" | "failed";
|
|
615
|
+
timeout: number;
|
|
616
|
+
cwd: string;
|
|
617
|
+
id: string;
|
|
618
|
+
memory: number;
|
|
619
|
+
vcpus: number;
|
|
620
|
+
runtime: string;
|
|
621
|
+
requestedAt: number;
|
|
622
|
+
createdAt: number;
|
|
623
|
+
updatedAt: number;
|
|
624
|
+
duration?: number | undefined;
|
|
625
|
+
startedAt?: number | undefined;
|
|
626
|
+
requestedStopAt?: number | undefined;
|
|
627
|
+
stoppedAt?: number | undefined;
|
|
628
|
+
};
|
|
629
|
+
}>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SandboxesResponse = exports.LogLine = exports.EmptyResponse = exports.CommandFinishedResponse = exports.CommandResponse = exports.SandboxAndRoutesResponse = exports.SandboxResponse = exports.Command = exports.Pagination = exports.SandboxRoute = exports.Sandbox = void 0;
|
|
3
|
+
exports.ExtendTimeoutResponse = exports.SandboxesResponse = exports.LogLine = exports.EmptyResponse = exports.CommandFinishedResponse = exports.CommandResponse = exports.SandboxAndRoutesResponse = exports.SandboxResponse = exports.Command = exports.Pagination = exports.SandboxRoute = exports.Sandbox = void 0;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
5
|
exports.Sandbox = zod_1.z.object({
|
|
6
6
|
id: zod_1.z.string(),
|
|
@@ -74,3 +74,6 @@ exports.SandboxesResponse = zod_1.z.object({
|
|
|
74
74
|
sandboxes: zod_1.z.array(exports.Sandbox),
|
|
75
75
|
pagination: exports.Pagination,
|
|
76
76
|
});
|
|
77
|
+
exports.ExtendTimeoutResponse = zod_1.z.object({
|
|
78
|
+
sandbox: exports.Sandbox,
|
|
79
|
+
});
|
package/dist/command.d.ts
CHANGED
|
@@ -88,9 +88,13 @@ export declare class Command {
|
|
|
88
88
|
* }
|
|
89
89
|
* ```
|
|
90
90
|
*
|
|
91
|
+
* @param params - Optional parameters.
|
|
92
|
+
* @param params.signal - An AbortSignal to cancel waiting.
|
|
91
93
|
* @returns A {@link CommandFinished} instance with populated exit code.
|
|
92
94
|
*/
|
|
93
|
-
wait(
|
|
95
|
+
wait(params?: {
|
|
96
|
+
signal?: AbortSignal;
|
|
97
|
+
}): Promise<CommandFinished>;
|
|
94
98
|
/**
|
|
95
99
|
* Get the output of `stdout`, `stderr`, or both as a string.
|
|
96
100
|
*
|
|
@@ -98,35 +102,50 @@ export declare class Command {
|
|
|
98
102
|
* not output valid Unicode.
|
|
99
103
|
*
|
|
100
104
|
* @param stream - The output stream to read: "stdout", "stderr", or "both".
|
|
105
|
+
* @param opts - Optional parameters.
|
|
106
|
+
* @param opts.signal - An AbortSignal to cancel output streaming.
|
|
101
107
|
* @returns The output of the specified stream(s) as a string.
|
|
102
108
|
*/
|
|
103
|
-
output(stream?: "stdout" | "stderr" | "both"
|
|
109
|
+
output(stream?: "stdout" | "stderr" | "both", opts?: {
|
|
110
|
+
signal?: AbortSignal;
|
|
111
|
+
}): Promise<string>;
|
|
104
112
|
/**
|
|
105
113
|
* Get the output of `stdout` as a string.
|
|
106
114
|
*
|
|
107
115
|
* NOTE: This may throw string conversion errors if the command does
|
|
108
116
|
* not output valid Unicode.
|
|
109
117
|
*
|
|
118
|
+
* @param opts - Optional parameters.
|
|
119
|
+
* @param opts.signal - An AbortSignal to cancel output streaming.
|
|
110
120
|
* @returns The standard output of the command.
|
|
111
121
|
*/
|
|
112
|
-
stdout(
|
|
122
|
+
stdout(opts?: {
|
|
123
|
+
signal?: AbortSignal;
|
|
124
|
+
}): Promise<string>;
|
|
113
125
|
/**
|
|
114
126
|
* Get the output of `stderr` as a string.
|
|
115
127
|
*
|
|
116
128
|
* NOTE: This may throw string conversion errors if the command does
|
|
117
129
|
* not output valid Unicode.
|
|
118
130
|
*
|
|
131
|
+
* @param opts - Optional parameters.
|
|
132
|
+
* @param opts.signal - An AbortSignal to cancel output streaming.
|
|
119
133
|
* @returns The standard error output of the command.
|
|
120
134
|
*/
|
|
121
|
-
stderr(
|
|
135
|
+
stderr(opts?: {
|
|
136
|
+
signal?: AbortSignal;
|
|
137
|
+
}): Promise<string>;
|
|
122
138
|
/**
|
|
123
139
|
* Kill a running command in a sandbox.
|
|
124
140
|
*
|
|
125
|
-
* @param
|
|
126
|
-
*
|
|
141
|
+
* @param signal - The signal to send the running process. Defaults to SIGTERM.
|
|
142
|
+
* @param opts - Optional parameters.
|
|
143
|
+
* @param opts.abortSignal - An AbortSignal to cancel the kill operation.
|
|
127
144
|
* @returns Promise<void>.
|
|
128
145
|
*/
|
|
129
|
-
kill(signal?: Signal
|
|
146
|
+
kill(signal?: Signal, opts?: {
|
|
147
|
+
abortSignal?: AbortSignal;
|
|
148
|
+
}): Promise<void>;
|
|
130
149
|
}
|
|
131
150
|
/**
|
|
132
151
|
* A command that has finished executing.
|
package/dist/command.js
CHANGED
|
@@ -82,13 +82,17 @@ class Command {
|
|
|
82
82
|
* }
|
|
83
83
|
* ```
|
|
84
84
|
*
|
|
85
|
+
* @param params - Optional parameters.
|
|
86
|
+
* @param params.signal - An AbortSignal to cancel waiting.
|
|
85
87
|
* @returns A {@link CommandFinished} instance with populated exit code.
|
|
86
88
|
*/
|
|
87
|
-
async wait() {
|
|
89
|
+
async wait(params) {
|
|
90
|
+
params?.signal?.throwIfAborted();
|
|
88
91
|
const command = await this.client.getCommand({
|
|
89
92
|
sandboxId: this.sandboxId,
|
|
90
93
|
cmdId: this.cmd.id,
|
|
91
94
|
wait: true,
|
|
95
|
+
signal: params?.signal,
|
|
92
96
|
});
|
|
93
97
|
return new CommandFinished({
|
|
94
98
|
client: this.client,
|
|
@@ -104,11 +108,13 @@ class Command {
|
|
|
104
108
|
* not output valid Unicode.
|
|
105
109
|
*
|
|
106
110
|
* @param stream - The output stream to read: "stdout", "stderr", or "both".
|
|
111
|
+
* @param opts - Optional parameters.
|
|
112
|
+
* @param opts.signal - An AbortSignal to cancel output streaming.
|
|
107
113
|
* @returns The output of the specified stream(s) as a string.
|
|
108
114
|
*/
|
|
109
|
-
async output(stream = "both") {
|
|
115
|
+
async output(stream = "both", opts) {
|
|
110
116
|
let data = "";
|
|
111
|
-
for await (const log of this.logs()) {
|
|
117
|
+
for await (const log of this.logs({ signal: opts?.signal })) {
|
|
112
118
|
if (stream === "both" || log.stream === stream) {
|
|
113
119
|
data += log.data;
|
|
114
120
|
}
|
|
@@ -121,10 +127,12 @@ class Command {
|
|
|
121
127
|
* NOTE: This may throw string conversion errors if the command does
|
|
122
128
|
* not output valid Unicode.
|
|
123
129
|
*
|
|
130
|
+
* @param opts - Optional parameters.
|
|
131
|
+
* @param opts.signal - An AbortSignal to cancel output streaming.
|
|
124
132
|
* @returns The standard output of the command.
|
|
125
133
|
*/
|
|
126
|
-
async stdout() {
|
|
127
|
-
return this.output("stdout");
|
|
134
|
+
async stdout(opts) {
|
|
135
|
+
return this.output("stdout", opts);
|
|
128
136
|
}
|
|
129
137
|
/**
|
|
130
138
|
* Get the output of `stderr` as a string.
|
|
@@ -132,23 +140,27 @@ class Command {
|
|
|
132
140
|
* NOTE: This may throw string conversion errors if the command does
|
|
133
141
|
* not output valid Unicode.
|
|
134
142
|
*
|
|
143
|
+
* @param opts - Optional parameters.
|
|
144
|
+
* @param opts.signal - An AbortSignal to cancel output streaming.
|
|
135
145
|
* @returns The standard error output of the command.
|
|
136
146
|
*/
|
|
137
|
-
async stderr() {
|
|
138
|
-
return this.output("stderr");
|
|
147
|
+
async stderr(opts) {
|
|
148
|
+
return this.output("stderr", opts);
|
|
139
149
|
}
|
|
140
150
|
/**
|
|
141
151
|
* Kill a running command in a sandbox.
|
|
142
152
|
*
|
|
143
|
-
* @param
|
|
144
|
-
*
|
|
153
|
+
* @param signal - The signal to send the running process. Defaults to SIGTERM.
|
|
154
|
+
* @param opts - Optional parameters.
|
|
155
|
+
* @param opts.abortSignal - An AbortSignal to cancel the kill operation.
|
|
145
156
|
* @returns Promise<void>.
|
|
146
157
|
*/
|
|
147
|
-
async kill(signal) {
|
|
158
|
+
async kill(signal, opts) {
|
|
148
159
|
await this.client.killCommand({
|
|
149
160
|
sandboxId: this.sandboxId,
|
|
150
161
|
commandId: this.cmd.id,
|
|
151
162
|
signal: (0, resolveSignal_1.resolveSignal)(signal ?? "SIGTERM"),
|
|
163
|
+
abortSignal: opts?.abortSignal,
|
|
152
164
|
});
|
|
153
165
|
}
|
|
154
166
|
}
|
package/dist/sandbox.d.ts
CHANGED
|
@@ -54,6 +54,10 @@ export interface CreateSandboxParams {
|
|
|
54
54
|
* If not specified, the default runtime `node22` will be used.
|
|
55
55
|
*/
|
|
56
56
|
runtime?: "node22" | "python3.13" | (string & {});
|
|
57
|
+
/**
|
|
58
|
+
* An AbortSignal to cancel sandbox creation.
|
|
59
|
+
*/
|
|
60
|
+
signal?: AbortSignal;
|
|
57
61
|
}
|
|
58
62
|
/** @inline */
|
|
59
63
|
interface GetSandboxParams {
|
|
@@ -61,6 +65,10 @@ interface GetSandboxParams {
|
|
|
61
65
|
* Unique identifier of the sandbox.
|
|
62
66
|
*/
|
|
63
67
|
sandboxId: string;
|
|
68
|
+
/**
|
|
69
|
+
* An AbortSignal to cancel the operation.
|
|
70
|
+
*/
|
|
71
|
+
signal?: AbortSignal;
|
|
64
72
|
}
|
|
65
73
|
/** @inline */
|
|
66
74
|
interface RunCommandParams {
|
|
@@ -96,6 +104,10 @@ interface RunCommandParams {
|
|
|
96
104
|
* A `Writable` stream where `stderr` from the command will be piped
|
|
97
105
|
*/
|
|
98
106
|
stderr?: Writable;
|
|
107
|
+
/**
|
|
108
|
+
* An AbortSignal to cancel the command execution
|
|
109
|
+
*/
|
|
110
|
+
signal?: AbortSignal;
|
|
99
111
|
}
|
|
100
112
|
/**
|
|
101
113
|
* A Sandbox is an isolated Linux MicroVM to run commands in.
|
|
@@ -118,10 +130,14 @@ export declare class Sandbox {
|
|
|
118
130
|
* The status of the sandbox.
|
|
119
131
|
*/
|
|
120
132
|
get status(): SandboxMetaData["status"];
|
|
133
|
+
/**
|
|
134
|
+
* The timeout of the sandbox in milliseconds.
|
|
135
|
+
*/
|
|
136
|
+
get timeout(): number;
|
|
121
137
|
/**
|
|
122
138
|
* Internal metadata about this sandbox.
|
|
123
139
|
*/
|
|
124
|
-
private
|
|
140
|
+
private sandbox;
|
|
125
141
|
/**
|
|
126
142
|
* Allow to get a list of sandboxes for a team narrowed to the given params.
|
|
127
143
|
* It returns both the sandboxes and the pagination metadata to allow getting
|
|
@@ -181,17 +197,25 @@ export declare class Sandbox {
|
|
|
181
197
|
* Get a previously run command by its ID.
|
|
182
198
|
*
|
|
183
199
|
* @param cmdId - ID of the command to retrieve
|
|
200
|
+
* @param opts - Optional parameters.
|
|
201
|
+
* @param opts.signal - An AbortSignal to cancel the operation.
|
|
184
202
|
* @returns A {@link Command} instance representing the command
|
|
185
203
|
*/
|
|
186
|
-
getCommand(cmdId: string
|
|
204
|
+
getCommand(cmdId: string, opts?: {
|
|
205
|
+
signal?: AbortSignal;
|
|
206
|
+
}): Promise<Command>;
|
|
187
207
|
/**
|
|
188
208
|
* Start executing a command in this sandbox.
|
|
189
209
|
*
|
|
190
210
|
* @param command - The command to execute.
|
|
191
211
|
* @param args - Arguments to pass to the command.
|
|
212
|
+
* @param opts - Optional parameters.
|
|
213
|
+
* @param opts.signal - An AbortSignal to cancel the command execution.
|
|
192
214
|
* @returns A {@link CommandFinished} result once execution is done.
|
|
193
215
|
*/
|
|
194
|
-
runCommand(command: string, args?: string[]
|
|
216
|
+
runCommand(command: string, args?: string[], opts?: {
|
|
217
|
+
signal?: AbortSignal;
|
|
218
|
+
}): Promise<CommandFinished>;
|
|
195
219
|
/**
|
|
196
220
|
* Start executing a command in detached mode.
|
|
197
221
|
*
|
|
@@ -220,17 +244,25 @@ export declare class Sandbox {
|
|
|
220
244
|
* Create a directory in the filesystem of this sandbox.
|
|
221
245
|
*
|
|
222
246
|
* @param path - Path of the directory to create
|
|
247
|
+
* @param opts - Optional parameters.
|
|
248
|
+
* @param opts.signal - An AbortSignal to cancel the operation.
|
|
223
249
|
*/
|
|
224
|
-
mkDir(path: string
|
|
250
|
+
mkDir(path: string, opts?: {
|
|
251
|
+
signal?: AbortSignal;
|
|
252
|
+
}): Promise<void>;
|
|
225
253
|
/**
|
|
226
254
|
* Read a file from the filesystem of this sandbox.
|
|
227
255
|
*
|
|
228
256
|
* @param file - File to read, with path and optional cwd
|
|
257
|
+
* @param opts - Optional parameters.
|
|
258
|
+
* @param opts.signal - An AbortSignal to cancel the operation.
|
|
229
259
|
* @returns A promise that resolves to a ReadableStream containing the file contents
|
|
230
260
|
*/
|
|
231
261
|
readFile(file: {
|
|
232
262
|
path: string;
|
|
233
263
|
cwd?: string;
|
|
264
|
+
}, opts?: {
|
|
265
|
+
signal?: AbortSignal;
|
|
234
266
|
}): Promise<NodeJS.ReadableStream | null>;
|
|
235
267
|
/**
|
|
236
268
|
* Write files to the filesystem of this sandbox.
|
|
@@ -238,12 +270,16 @@ export declare class Sandbox {
|
|
|
238
270
|
* Writes files using the `vercel-sandbox` user.
|
|
239
271
|
*
|
|
240
272
|
* @param files - Array of files with path and stream/buffer contents
|
|
273
|
+
* @param opts - Optional parameters.
|
|
274
|
+
* @param opts.signal - An AbortSignal to cancel the operation.
|
|
241
275
|
* @returns A promise that resolves when the files are written
|
|
242
276
|
*/
|
|
243
277
|
writeFiles(files: {
|
|
244
278
|
path: string;
|
|
245
279
|
content: Buffer;
|
|
246
|
-
}[]
|
|
280
|
+
}[], opts?: {
|
|
281
|
+
signal?: AbortSignal;
|
|
282
|
+
}): Promise<void>;
|
|
247
283
|
/**
|
|
248
284
|
* Get the public domain of a port of this sandbox.
|
|
249
285
|
*
|
|
@@ -255,8 +291,26 @@ export declare class Sandbox {
|
|
|
255
291
|
/**
|
|
256
292
|
* Stop the sandbox.
|
|
257
293
|
*
|
|
294
|
+
* @param opts - Optional parameters.
|
|
295
|
+
* @param opts.signal - An AbortSignal to cancel the operation.
|
|
258
296
|
* @returns A promise that resolves when the sandbox is stopped
|
|
259
297
|
*/
|
|
260
|
-
stop(
|
|
298
|
+
stop(opts?: {
|
|
299
|
+
signal?: AbortSignal;
|
|
300
|
+
}): Promise<void>;
|
|
301
|
+
/**
|
|
302
|
+
* Extend the timeout of the sandbox by the specified duration.
|
|
303
|
+
*
|
|
304
|
+
* This allows you to extend the lifetime of a sandbox up until the maximum
|
|
305
|
+
* execution timeout for your plan.
|
|
306
|
+
*
|
|
307
|
+
* @param duration - The duration in milliseconds to extend the timeout by
|
|
308
|
+
* @param opts - Optional parameters.
|
|
309
|
+
* @param opts.signal - An AbortSignal to cancel the operation.
|
|
310
|
+
* @returns A promise that resolves when the timeout is extended
|
|
311
|
+
*/
|
|
312
|
+
extendTimeout(duration: number, opts?: {
|
|
313
|
+
signal?: AbortSignal;
|
|
314
|
+
}): Promise<void>;
|
|
261
315
|
}
|
|
262
316
|
export {};
|