@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.
@@ -1,4 +1,4 @@
1
1
 
2
- > @vercel/sandbox@0.0.3 build /home/runner/work/sandbox-sdk/sandbox-sdk/packages/sandbox
2
+ > @vercel/sandbox@0.0.5 build /home/runner/work/sandbox-sdk/sandbox-sdk/packages/sandbox
3
3
  > tsc
4
4
 
@@ -1,4 +1,4 @@
1
1
 
2
- > @vercel/sandbox@0.0.3 typecheck /home/runner/work/sandbox-sdk/sandbox-sdk/packages/sandbox
2
+ > @vercel/sandbox@0.0.5 typecheck /home/runner/work/sandbox-sdk/sandbox-sdk/packages/sandbox
3
3
  > tsc --noEmit
4
4
 
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
- - Go to your team settings, and copy the team ID.
16
- - Go to your Vercel account settings and [create a token][create-token]. Make
17
- sure it is scoped to the team ID from the previous step.
18
- - Create a new project:
19
-
20
- ```
21
- $ mkdir sandbox-test
22
- $ pnpm init
23
- $ pnpm add @vercel/sandbox
24
- $ pnpm add --save-dev tsx
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 `whoami.ts`:
28
+ Now create `next-dev.ts`:
28
29
 
29
- {@includeCode ../cli/src/example-whoami.ts}
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
- Now have a look at the sidebar for which classes exist.
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
 
@@ -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
  }>>;
@@ -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
  }
@@ -1,37 +1,58 @@
1
1
  import { SandboxClient } from "./client/client";
2
2
  import { Readable } from "stream";
3
3
  /**
4
- * Create a new instance of the SandboxSDK.
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
- * const teamId = process.env.VERCEL_TEAM_ID
8
- * const token = process.env.VERCEL_TOKEN
9
- * const sdk = new SandboxSDK({ teamId: teamId!, token: token! });
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 SandboxSDK {
15
- client: SandboxClient;
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
- * Create a new Sandbox with the given resources, source code, and ports.
34
+ * Creates a new sandbox instance using the provided Git repository and exposed ports.
22
35
  *
23
- * Upon start, the sandbox will perform a `git clone` of the repository given.
24
- * This repo needs to be public.
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
- * @returns a
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
- ports: number[];
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 SandboxSDK.createSandbox} to construct a Sandbox.
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
- * @param command
74
- * @param args
75
- * @returns
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 {};
@@ -1,36 +1,54 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Command = exports.Sandbox = exports.SandboxSDK = void 0;
3
+ exports.Command = exports.Sandbox = exports.SDK = void 0;
4
4
  const client_1 = require("./client/client");
5
5
  /**
6
- * Create a new instance of the SandboxSDK.
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
- * const teamId = process.env.VERCEL_TEAM_ID
10
- * const token = process.env.VERCEL_TOKEN
11
- * const sdk = new SandboxSDK({ teamId: teamId!, token: token! });
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 SandboxSDK {
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
- * Create a new Sandbox with the given resources, source code, and ports.
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
- * Upon start, the sandbox will perform a `git clone` of the repository given.
24
- * This repo needs to be public.
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
- * @param params
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
- ports: params.ports,
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.SandboxSDK = SandboxSDK;
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 SandboxSDK.createSandbox} to construct a Sandbox.
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
- * Start executing a command in this sandbox.
66
- * @param command
67
- * @param args
68
- * @returns
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 { SandboxSDK, Sandbox, Command } from "./create-sandbox";
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.SandboxClient = exports.Command = exports.Sandbox = exports.SandboxSDK = void 0;
3
+ exports.Command = exports.Sandbox = exports.SDK = void 0;
4
4
  var create_sandbox_1 = require("./create-sandbox");
5
- Object.defineProperty(exports, "SandboxSDK", { enumerable: true, get: function () { return create_sandbox_1.SandboxSDK; } });
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.3";
1
+ export declare const VERSION = "0.0.5";
package/dist/version.js CHANGED
@@ -2,4 +2,4 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VERSION = void 0;
4
4
  // Autogenerated by inject-version.ts
5
- exports.VERSION = "0.0.3";
5
+ exports.VERSION = "0.0.5";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/sandbox",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -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
  );
@@ -2,41 +2,63 @@ import { SandboxClient } from "./client/client";
2
2
  import { Readable } from "stream";
3
3
 
4
4
  /**
5
- * Create a new instance of the SandboxSDK.
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
- * const teamId = process.env.VERCEL_TEAM_ID
9
- * const token = process.env.VERCEL_TOKEN
10
- * const sdk = new SandboxSDK({ teamId: teamId!, token: token! });
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 SandboxSDK {
16
- public client: SandboxClient;
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
- * Create a new Sandbox with the given resources, source code, and ports.
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
- * Upon start, the sandbox will perform a `git clone` of the repository given.
26
- * This repo needs to be public.
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
- * @param params
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
- ports: number[];
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
- ports: params.ports,
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 SandboxSDK.createSandbox} to construct a Sandbox.
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
- * @param command
100
- * @param args
101
- * @returns
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(command: string, args: string[] = []) {
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 { SandboxSDK, Sandbox, Command } from "./create-sandbox";
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.3";
2
+ export const VERSION = "0.0.5";