@vercel/sandbox 0.0.3 → 0.0.5
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/README.md +23 -17
- package/dist/client/client.d.ts +3 -1
- package/dist/client/client.js +2 -0
- package/dist/create-sandbox.d.ts +63 -19
- package/dist/create-sandbox.js +45 -26
- package/dist/index.d.ts +1 -2
- package/dist/index.js +2 -4
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
- package/src/client/client.ts +5 -1
- package/src/create-sandbox.ts +81 -23
- package/src/index.ts +1 -2
- 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.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Allow specifying env vars and cwd when running commands ([#25](https://github.com/vercel/sandbox-sdk/pull/25))
|
|
8
|
+
|
|
9
|
+
- createSandbox: do not require ports to be specified ([#27](https://github.com/vercel/sandbox-sdk/pull/27))
|
|
10
|
+
|
|
11
|
+
## 0.0.4
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- Rename `SandboxSDK` to `SDK` and incorporate `projectId` as a required parameter ([#21](https://github.com/vercel/sandbox-sdk/pull/21))
|
|
16
|
+
|
|
3
17
|
## 0.0.3
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -12,31 +12,37 @@ infrastructure][hive] that powers 1M+ builds a day at Vercel.
|
|
|
12
12
|
Vercel Sandbox is in private beta. These examples will not work unless these
|
|
13
13
|
APIs are enabled for your team.
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
15
|
+
- Go to your team settings, and copy the team ID.
|
|
16
|
+
- Go to a project's settings, and copy the project ID.
|
|
17
|
+
- Go to your Vercel account settings and [create a token][create-token]. Make
|
|
18
|
+
sure it is scoped to the team ID from the previous step.
|
|
19
|
+
- Create a new project:
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
mkdir sandbox-test
|
|
23
|
+
cd sandbox-test
|
|
24
|
+
pnpm init
|
|
25
|
+
pnpm add @vercel/sandbox ms
|
|
25
26
|
```
|
|
26
27
|
|
|
27
|
-
Now create `
|
|
28
|
+
Now create `next-dev.ts`:
|
|
28
29
|
|
|
29
|
-
{@includeCode ../cli/src/example-
|
|
30
|
+
{@includeCode ../cli/src/example-next.ts}
|
|
30
31
|
|
|
31
32
|
Run it like this:
|
|
32
33
|
|
|
34
|
+
```sh
|
|
35
|
+
VERCEL_TEAM_ID=<team_id> VERCEL_TOKEN=<token> VERCEL_PROJECT_ID=<project_id> node --experimental-strip-types ./next-dev.ts
|
|
33
36
|
```
|
|
34
|
-
$ VERCEL_TEAM_ID=<team_id> VERCEL_TOKEN=<token> pnpm tsx ./whoami.ts
|
|
35
|
-
Running as: vercel-sandbox
|
|
36
|
-
Working dir: /vercel/sandbox
|
|
37
|
-
```
|
|
38
37
|
|
|
39
|
-
|
|
38
|
+
This will:
|
|
39
|
+
|
|
40
|
+
- Start a sandbox, seeding it with a git repository.
|
|
41
|
+
- Install dependencies.
|
|
42
|
+
- Run a `next dev` server
|
|
43
|
+
- Open it in your browser
|
|
44
|
+
|
|
45
|
+
All while streaming logs to your local terminal.
|
|
40
46
|
|
|
41
47
|
## Limitations
|
|
42
48
|
|
package/dist/client/client.d.ts
CHANGED
|
@@ -9,11 +9,12 @@ export declare class SandboxClient extends APIClient {
|
|
|
9
9
|
});
|
|
10
10
|
protected request(path: string, params?: RequestParams): Promise<import("node-fetch").Response>;
|
|
11
11
|
createSandbox(params: {
|
|
12
|
+
ports: number[];
|
|
13
|
+
projectId: string;
|
|
12
14
|
source: {
|
|
13
15
|
type: "git";
|
|
14
16
|
url: string;
|
|
15
17
|
};
|
|
16
|
-
ports: number[];
|
|
17
18
|
timeout?: number;
|
|
18
19
|
}): Promise<import("./base-client").Parsed<{
|
|
19
20
|
sandboxId: string;
|
|
@@ -27,6 +28,7 @@ export declare class SandboxClient extends APIClient {
|
|
|
27
28
|
cwd?: string;
|
|
28
29
|
command: string;
|
|
29
30
|
args: string[];
|
|
31
|
+
env: Record<string, string>;
|
|
30
32
|
}): Promise<import("./base-client").Parsed<{
|
|
31
33
|
cmdId: string;
|
|
32
34
|
}>>;
|
package/dist/client/client.js
CHANGED
|
@@ -36,6 +36,7 @@ class SandboxClient extends base_client_1.APIClient {
|
|
|
36
36
|
return (0, base_client_1.parseOrThrow)(validators_1.CreatedSandbox, await this.request("/v1/sandboxes", {
|
|
37
37
|
method: "POST",
|
|
38
38
|
body: JSON.stringify({
|
|
39
|
+
projectId: params.projectId,
|
|
39
40
|
ports: params.ports,
|
|
40
41
|
source: params.source,
|
|
41
42
|
timeout: params.timeout,
|
|
@@ -49,6 +50,7 @@ class SandboxClient extends base_client_1.APIClient {
|
|
|
49
50
|
command: params.command,
|
|
50
51
|
args: params.args,
|
|
51
52
|
cwd: params.cwd,
|
|
53
|
+
env: params.env,
|
|
52
54
|
}),
|
|
53
55
|
}));
|
|
54
56
|
}
|
package/dist/create-sandbox.d.ts
CHANGED
|
@@ -1,37 +1,58 @@
|
|
|
1
1
|
import { SandboxClient } from "./client/client";
|
|
2
2
|
import { Readable } from "stream";
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* SDK for interacting with the Sandbox API. Provides methods to create and
|
|
5
|
+
* manage sandboxes configured with specific source code and network ports.
|
|
5
6
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* const
|
|
9
|
-
*
|
|
10
|
-
*
|
|
7
|
+
* Example:
|
|
8
|
+
* ```ts
|
|
9
|
+
* const sdk = new SDK({
|
|
10
|
+
* teamId: process.env.VERCEL_TEAM_ID!,
|
|
11
|
+
* token: process.env.VERCEL_TOKEN!,
|
|
12
|
+
* });
|
|
13
|
+
* ```
|
|
11
14
|
*
|
|
12
|
-
* @see {@link createSandbox} to start a sandbox.
|
|
15
|
+
* @see {@link SDK.createSandbox} to start a new sandbox.
|
|
13
16
|
*/
|
|
14
|
-
export declare class
|
|
15
|
-
|
|
17
|
+
export declare class SDK {
|
|
18
|
+
/**
|
|
19
|
+
* Internal API client for communicating with the sandbox backend.
|
|
20
|
+
*/
|
|
21
|
+
private client;
|
|
22
|
+
/**
|
|
23
|
+
* Create a new instance of `SDK`.
|
|
24
|
+
*
|
|
25
|
+
* @param config - Configuration options for the SDK.
|
|
26
|
+
* @param config.teamId - The Vercel team ID used to scope the Sandbox.
|
|
27
|
+
* @param config.token - The API token used for authentication.
|
|
28
|
+
*/
|
|
16
29
|
constructor({ teamId, token }: {
|
|
17
30
|
teamId: string;
|
|
18
31
|
token: string;
|
|
19
32
|
});
|
|
20
33
|
/**
|
|
21
|
-
*
|
|
34
|
+
* Creates a new sandbox instance using the provided Git repository and exposed ports.
|
|
22
35
|
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
36
|
+
* The repository must be public. On start, the sandbox will clone the repository
|
|
37
|
+
* and expose the specified ports for access.
|
|
25
38
|
*
|
|
26
|
-
* @param params
|
|
27
|
-
* @
|
|
39
|
+
* @param params - Configuration parameters for the sandbox.
|
|
40
|
+
* @param params.source - The source of the sandbox, currently supports Git repositories only.
|
|
41
|
+
* @param params.source.type - Type of source, must be `"git"`.
|
|
42
|
+
* @param params.source.url - The URL of the public Git repository to clone.
|
|
43
|
+
* @param params.projectId - The Vercel project ID used to link the Sandbox to.
|
|
44
|
+
* @param params.ports - Array of port numbers to expose from the sandbox.
|
|
45
|
+
* @param params.timeout - (Optional) Timeout in seconds before the sandbox auto-terminates.
|
|
46
|
+
*
|
|
47
|
+
* @returns A promise that resolves to a `Sandbox` instance.
|
|
28
48
|
*/
|
|
29
49
|
createSandbox(params: {
|
|
30
50
|
source: {
|
|
31
51
|
type: "git";
|
|
32
52
|
url: string;
|
|
33
53
|
};
|
|
34
|
-
|
|
54
|
+
projectId: string;
|
|
55
|
+
ports?: number[];
|
|
35
56
|
timeout?: number;
|
|
36
57
|
}): Promise<Sandbox>;
|
|
37
58
|
/** @hidden */
|
|
@@ -43,10 +64,21 @@ export declare class SandboxSDK {
|
|
|
43
64
|
sandboxId: string;
|
|
44
65
|
}): Promise<Sandbox>;
|
|
45
66
|
}
|
|
67
|
+
/** @inline */
|
|
68
|
+
interface RunCommandParams {
|
|
69
|
+
/** The command to execute */
|
|
70
|
+
cmd: string;
|
|
71
|
+
/** Arguments to pass to the command */
|
|
72
|
+
args?: string[];
|
|
73
|
+
/** Working directory to execute the command in */
|
|
74
|
+
cwd?: string;
|
|
75
|
+
/** Environment variables to set for this command */
|
|
76
|
+
env?: Record<string, string>;
|
|
77
|
+
}
|
|
46
78
|
/**
|
|
47
79
|
* A Sandbox is an isolated Linux MicroVM that you can your experiments on.
|
|
48
80
|
*
|
|
49
|
-
* @see {@link
|
|
81
|
+
* @see {@link SDK.createSandbox} to construct a Sandbox.
|
|
50
82
|
* @hideconstructor
|
|
51
83
|
*/
|
|
52
84
|
export declare class Sandbox {
|
|
@@ -70,11 +102,22 @@ export declare class Sandbox {
|
|
|
70
102
|
});
|
|
71
103
|
/**
|
|
72
104
|
* Start executing a command in this sandbox.
|
|
73
|
-
*
|
|
74
|
-
* @param
|
|
75
|
-
* @
|
|
105
|
+
*
|
|
106
|
+
* @param command - The command to execute.
|
|
107
|
+
* @param args - Arguments to pass to the command.
|
|
108
|
+
*
|
|
109
|
+
* @returns A {@link Command} instance.
|
|
76
110
|
*/
|
|
77
111
|
runCommand(command: string, args?: string[]): Promise<Command>;
|
|
112
|
+
/**
|
|
113
|
+
* Start executing a command in this sandbox.
|
|
114
|
+
*
|
|
115
|
+
* @param params - What should be executed.
|
|
116
|
+
*
|
|
117
|
+
* @returns A {@link Command} instance.
|
|
118
|
+
*/
|
|
119
|
+
runCommand(params: RunCommandParams): Promise<Command>;
|
|
120
|
+
_runCommand(params: RunCommandParams): Promise<Command>;
|
|
78
121
|
/**
|
|
79
122
|
* Write files to the filesystem of this sandbox.
|
|
80
123
|
*/
|
|
@@ -173,3 +216,4 @@ export declare class Command {
|
|
|
173
216
|
*/
|
|
174
217
|
stderr(): Promise<string>;
|
|
175
218
|
}
|
|
219
|
+
export {};
|
package/dist/create-sandbox.js
CHANGED
|
@@ -1,36 +1,54 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Command = exports.Sandbox = exports.
|
|
3
|
+
exports.Command = exports.Sandbox = exports.SDK = void 0;
|
|
4
4
|
const client_1 = require("./client/client");
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* SDK for interacting with the Sandbox API. Provides methods to create and
|
|
7
|
+
* manage sandboxes configured with specific source code and network ports.
|
|
7
8
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* const
|
|
11
|
-
*
|
|
12
|
-
*
|
|
9
|
+
* Example:
|
|
10
|
+
* ```ts
|
|
11
|
+
* const sdk = new SDK({
|
|
12
|
+
* teamId: process.env.VERCEL_TEAM_ID!,
|
|
13
|
+
* token: process.env.VERCEL_TOKEN!,
|
|
14
|
+
* });
|
|
15
|
+
* ```
|
|
13
16
|
*
|
|
14
|
-
* @see {@link createSandbox} to start a sandbox.
|
|
17
|
+
* @see {@link SDK.createSandbox} to start a new sandbox.
|
|
15
18
|
*/
|
|
16
|
-
class
|
|
19
|
+
class SDK {
|
|
20
|
+
/**
|
|
21
|
+
* Create a new instance of `SDK`.
|
|
22
|
+
*
|
|
23
|
+
* @param config - Configuration options for the SDK.
|
|
24
|
+
* @param config.teamId - The Vercel team ID used to scope the Sandbox.
|
|
25
|
+
* @param config.token - The API token used for authentication.
|
|
26
|
+
*/
|
|
17
27
|
constructor({ teamId, token }) {
|
|
18
28
|
this.client = new client_1.SandboxClient({ teamId, token });
|
|
19
29
|
}
|
|
20
30
|
/**
|
|
21
|
-
*
|
|
31
|
+
* Creates a new sandbox instance using the provided Git repository and exposed ports.
|
|
32
|
+
*
|
|
33
|
+
* The repository must be public. On start, the sandbox will clone the repository
|
|
34
|
+
* and expose the specified ports for access.
|
|
22
35
|
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
36
|
+
* @param params - Configuration parameters for the sandbox.
|
|
37
|
+
* @param params.source - The source of the sandbox, currently supports Git repositories only.
|
|
38
|
+
* @param params.source.type - Type of source, must be `"git"`.
|
|
39
|
+
* @param params.source.url - The URL of the public Git repository to clone.
|
|
40
|
+
* @param params.projectId - The Vercel project ID used to link the Sandbox to.
|
|
41
|
+
* @param params.ports - Array of port numbers to expose from the sandbox.
|
|
42
|
+
* @param params.timeout - (Optional) Timeout in seconds before the sandbox auto-terminates.
|
|
25
43
|
*
|
|
26
|
-
* @
|
|
27
|
-
* @returns a
|
|
44
|
+
* @returns A promise that resolves to a `Sandbox` instance.
|
|
28
45
|
*/
|
|
29
46
|
async createSandbox(params) {
|
|
30
47
|
const { client } = this;
|
|
31
48
|
const sandbox = await client.createSandbox({
|
|
32
49
|
source: params.source,
|
|
33
|
-
|
|
50
|
+
projectId: params.projectId,
|
|
51
|
+
ports: params.ports ?? [],
|
|
34
52
|
timeout: params.timeout,
|
|
35
53
|
});
|
|
36
54
|
return new Sandbox({
|
|
@@ -48,11 +66,11 @@ class SandboxSDK {
|
|
|
48
66
|
});
|
|
49
67
|
}
|
|
50
68
|
}
|
|
51
|
-
exports.
|
|
69
|
+
exports.SDK = SDK;
|
|
52
70
|
/**
|
|
53
71
|
* A Sandbox is an isolated Linux MicroVM that you can your experiments on.
|
|
54
72
|
*
|
|
55
|
-
* @see {@link
|
|
73
|
+
* @see {@link SDK.createSandbox} to construct a Sandbox.
|
|
56
74
|
* @hideconstructor
|
|
57
75
|
*/
|
|
58
76
|
class Sandbox {
|
|
@@ -61,17 +79,18 @@ class Sandbox {
|
|
|
61
79
|
this.routes = routes;
|
|
62
80
|
this.sandboxId = sandboxId;
|
|
63
81
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
async runCommand(command, args = []) {
|
|
82
|
+
async runCommand(commandOrParams, args) {
|
|
83
|
+
return typeof commandOrParams === "string"
|
|
84
|
+
? this._runCommand({ cmd: commandOrParams, args })
|
|
85
|
+
: this._runCommand(commandOrParams);
|
|
86
|
+
}
|
|
87
|
+
async _runCommand(params) {
|
|
71
88
|
const commandResponse = await this.client.runCommand({
|
|
72
89
|
sandboxId: this.sandboxId,
|
|
73
|
-
command,
|
|
74
|
-
args,
|
|
90
|
+
command: params.cmd,
|
|
91
|
+
args: params.args ?? [],
|
|
92
|
+
cwd: params.cwd,
|
|
93
|
+
env: params.env ?? {},
|
|
75
94
|
});
|
|
76
95
|
return new Command({
|
|
77
96
|
client: this.client,
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export { SandboxClient } from "./client/client";
|
|
1
|
+
export { SDK, Sandbox, Command } from "./create-sandbox";
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.Command = exports.Sandbox = exports.SDK = void 0;
|
|
4
4
|
var create_sandbox_1 = require("./create-sandbox");
|
|
5
|
-
Object.defineProperty(exports, "
|
|
5
|
+
Object.defineProperty(exports, "SDK", { enumerable: true, get: function () { return create_sandbox_1.SDK; } });
|
|
6
6
|
Object.defineProperty(exports, "Sandbox", { enumerable: true, get: function () { return create_sandbox_1.Sandbox; } });
|
|
7
7
|
Object.defineProperty(exports, "Command", { enumerable: true, get: function () { return create_sandbox_1.Command; } });
|
|
8
|
-
var client_1 = require("./client/client");
|
|
9
|
-
Object.defineProperty(exports, "SandboxClient", { enumerable: true, get: function () { return client_1.SandboxClient; } });
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "0.0.
|
|
1
|
+
export declare const VERSION = "0.0.5";
|
package/dist/version.js
CHANGED
package/package.json
CHANGED
package/src/client/client.ts
CHANGED
|
@@ -41,8 +41,9 @@ export class SandboxClient extends APIClient {
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
async createSandbox(params: {
|
|
44
|
-
source: { type: "git"; url: string };
|
|
45
44
|
ports: number[];
|
|
45
|
+
projectId: string;
|
|
46
|
+
source: { type: "git"; url: string };
|
|
46
47
|
timeout?: number;
|
|
47
48
|
}) {
|
|
48
49
|
return parseOrThrow(
|
|
@@ -50,6 +51,7 @@ export class SandboxClient extends APIClient {
|
|
|
50
51
|
await this.request("/v1/sandboxes", {
|
|
51
52
|
method: "POST",
|
|
52
53
|
body: JSON.stringify({
|
|
54
|
+
projectId: params.projectId,
|
|
53
55
|
ports: params.ports,
|
|
54
56
|
source: params.source,
|
|
55
57
|
timeout: params.timeout,
|
|
@@ -63,6 +65,7 @@ export class SandboxClient extends APIClient {
|
|
|
63
65
|
cwd?: string;
|
|
64
66
|
command: string;
|
|
65
67
|
args: string[];
|
|
68
|
+
env: Record<string, string>;
|
|
66
69
|
}) {
|
|
67
70
|
return parseOrThrow(
|
|
68
71
|
CreatedCommand,
|
|
@@ -72,6 +75,7 @@ export class SandboxClient extends APIClient {
|
|
|
72
75
|
command: params.command,
|
|
73
76
|
args: params.args,
|
|
74
77
|
cwd: params.cwd,
|
|
78
|
+
env: params.env,
|
|
75
79
|
}),
|
|
76
80
|
}),
|
|
77
81
|
);
|
package/src/create-sandbox.ts
CHANGED
|
@@ -2,41 +2,63 @@ import { SandboxClient } from "./client/client";
|
|
|
2
2
|
import { Readable } from "stream";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* SDK for interacting with the Sandbox API. Provides methods to create and
|
|
6
|
+
* manage sandboxes configured with specific source code and network ports.
|
|
6
7
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* const
|
|
10
|
-
*
|
|
11
|
-
*
|
|
8
|
+
* Example:
|
|
9
|
+
* ```ts
|
|
10
|
+
* const sdk = new SDK({
|
|
11
|
+
* teamId: process.env.VERCEL_TEAM_ID!,
|
|
12
|
+
* token: process.env.VERCEL_TOKEN!,
|
|
13
|
+
* });
|
|
14
|
+
* ```
|
|
12
15
|
*
|
|
13
|
-
* @see {@link createSandbox} to start a sandbox.
|
|
16
|
+
* @see {@link SDK.createSandbox} to start a new sandbox.
|
|
14
17
|
*/
|
|
15
|
-
export class
|
|
16
|
-
|
|
18
|
+
export class SDK {
|
|
19
|
+
/**
|
|
20
|
+
* Internal API client for communicating with the sandbox backend.
|
|
21
|
+
*/
|
|
22
|
+
private client: SandboxClient;
|
|
17
23
|
|
|
24
|
+
/**
|
|
25
|
+
* Create a new instance of `SDK`.
|
|
26
|
+
*
|
|
27
|
+
* @param config - Configuration options for the SDK.
|
|
28
|
+
* @param config.teamId - The Vercel team ID used to scope the Sandbox.
|
|
29
|
+
* @param config.token - The API token used for authentication.
|
|
30
|
+
*/
|
|
18
31
|
constructor({ teamId, token }: { teamId: string; token: string }) {
|
|
19
32
|
this.client = new SandboxClient({ teamId, token });
|
|
20
33
|
}
|
|
21
34
|
|
|
22
35
|
/**
|
|
23
|
-
*
|
|
36
|
+
* Creates a new sandbox instance using the provided Git repository and exposed ports.
|
|
37
|
+
*
|
|
38
|
+
* The repository must be public. On start, the sandbox will clone the repository
|
|
39
|
+
* and expose the specified ports for access.
|
|
24
40
|
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
41
|
+
* @param params - Configuration parameters for the sandbox.
|
|
42
|
+
* @param params.source - The source of the sandbox, currently supports Git repositories only.
|
|
43
|
+
* @param params.source.type - Type of source, must be `"git"`.
|
|
44
|
+
* @param params.source.url - The URL of the public Git repository to clone.
|
|
45
|
+
* @param params.projectId - The Vercel project ID used to link the Sandbox to.
|
|
46
|
+
* @param params.ports - Array of port numbers to expose from the sandbox.
|
|
47
|
+
* @param params.timeout - (Optional) Timeout in seconds before the sandbox auto-terminates.
|
|
27
48
|
*
|
|
28
|
-
* @
|
|
29
|
-
* @returns a
|
|
49
|
+
* @returns A promise that resolves to a `Sandbox` instance.
|
|
30
50
|
*/
|
|
31
51
|
async createSandbox(params: {
|
|
32
52
|
source: { type: "git"; url: string };
|
|
33
|
-
|
|
53
|
+
projectId: string;
|
|
54
|
+
ports?: number[];
|
|
34
55
|
timeout?: number;
|
|
35
56
|
}) {
|
|
36
57
|
const { client } = this;
|
|
37
58
|
const sandbox = await client.createSandbox({
|
|
38
59
|
source: params.source,
|
|
39
|
-
|
|
60
|
+
projectId: params.projectId,
|
|
61
|
+
ports: params.ports ?? [],
|
|
40
62
|
timeout: params.timeout,
|
|
41
63
|
});
|
|
42
64
|
|
|
@@ -63,10 +85,22 @@ export class SandboxSDK {
|
|
|
63
85
|
}
|
|
64
86
|
}
|
|
65
87
|
|
|
88
|
+
/** @inline */
|
|
89
|
+
interface RunCommandParams {
|
|
90
|
+
/** The command to execute */
|
|
91
|
+
cmd: string;
|
|
92
|
+
/** Arguments to pass to the command */
|
|
93
|
+
args?: string[];
|
|
94
|
+
/** Working directory to execute the command in */
|
|
95
|
+
cwd?: string;
|
|
96
|
+
/** Environment variables to set for this command */
|
|
97
|
+
env?: Record<string, string>;
|
|
98
|
+
}
|
|
99
|
+
|
|
66
100
|
/**
|
|
67
101
|
* A Sandbox is an isolated Linux MicroVM that you can your experiments on.
|
|
68
102
|
*
|
|
69
|
-
* @see {@link
|
|
103
|
+
* @see {@link SDK.createSandbox} to construct a Sandbox.
|
|
70
104
|
* @hideconstructor
|
|
71
105
|
*/
|
|
72
106
|
export class Sandbox {
|
|
@@ -96,15 +130,39 @@ export class Sandbox {
|
|
|
96
130
|
|
|
97
131
|
/**
|
|
98
132
|
* Start executing a command in this sandbox.
|
|
99
|
-
*
|
|
100
|
-
* @param
|
|
101
|
-
* @
|
|
133
|
+
*
|
|
134
|
+
* @param command - The command to execute.
|
|
135
|
+
* @param args - Arguments to pass to the command.
|
|
136
|
+
*
|
|
137
|
+
* @returns A {@link Command} instance.
|
|
138
|
+
*/
|
|
139
|
+
async runCommand(command: string, args?: string[]): Promise<Command>;
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Start executing a command in this sandbox.
|
|
143
|
+
*
|
|
144
|
+
* @param params - What should be executed.
|
|
145
|
+
*
|
|
146
|
+
* @returns A {@link Command} instance.
|
|
102
147
|
*/
|
|
103
|
-
async runCommand(
|
|
148
|
+
async runCommand(params: RunCommandParams): Promise<Command>;
|
|
149
|
+
|
|
150
|
+
async runCommand(
|
|
151
|
+
commandOrParams: string | RunCommandParams,
|
|
152
|
+
args?: string[],
|
|
153
|
+
): Promise<Command> {
|
|
154
|
+
return typeof commandOrParams === "string"
|
|
155
|
+
? this._runCommand({ cmd: commandOrParams, args })
|
|
156
|
+
: this._runCommand(commandOrParams);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
async _runCommand(params: RunCommandParams) {
|
|
104
160
|
const commandResponse = await this.client.runCommand({
|
|
105
161
|
sandboxId: this.sandboxId,
|
|
106
|
-
command,
|
|
107
|
-
args,
|
|
162
|
+
command: params.cmd,
|
|
163
|
+
args: params.args ?? [],
|
|
164
|
+
cwd: params.cwd,
|
|
165
|
+
env: params.env ?? {},
|
|
108
166
|
});
|
|
109
167
|
|
|
110
168
|
return new Command({
|
package/src/index.ts
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export { SandboxClient } from "./client/client";
|
|
1
|
+
export { SDK, Sandbox, Command } from "./create-sandbox";
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Autogenerated by inject-version.ts
|
|
2
|
-
export const VERSION = "0.0.
|
|
2
|
+
export const VERSION = "0.0.5";
|