eve 0.36.0 → 0.37.0

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.
Files changed (68) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/README.md +1 -0
  3. package/dist/src/cli/commands/agent-instructions.d.ts +4 -4
  4. package/dist/src/cli/commands/init-confirm.d.ts +12 -0
  5. package/dist/src/cli/commands/init-confirm.js +1 -0
  6. package/dist/src/cli/commands/init.d.ts +6 -5
  7. package/dist/src/cli/commands/init.js +1 -1
  8. package/dist/src/cli/run.d.ts +1 -0
  9. package/dist/src/cli/run.js +3 -3
  10. package/dist/src/compiled/.vendor-stamp.json +2 -1
  11. package/dist/src/compiled/@vercel/sandbox/api-client/api-client.d.ts +339 -0
  12. package/dist/src/compiled/@vercel/sandbox/api-client/index.d.ts +1 -1
  13. package/dist/src/compiled/@vercel/sandbox/api-client/validators.d.ts +25 -1
  14. package/dist/src/compiled/@vercel/sandbox/drive.d.ts +140 -0
  15. package/dist/src/compiled/@vercel/sandbox/index.d.ts +3 -2
  16. package/dist/src/compiled/@vercel/sandbox/index.js +13 -13
  17. package/dist/src/compiled/@vercel/sandbox/sandbox.d.ts +55 -18
  18. package/dist/src/compiled/@vercel/sandbox-stable/LICENSE +201 -0
  19. package/dist/src/compiled/@vercel/sandbox-stable/_async-retry.d.ts +8 -0
  20. package/dist/src/compiled/@vercel/sandbox-stable/_workflow-serde.d.ts +5 -0
  21. package/dist/src/compiled/@vercel/sandbox-stable/api-client/api-client.d.ts +1456 -0
  22. package/dist/src/compiled/@vercel/sandbox-stable/api-client/api-error.d.ts +29 -0
  23. package/dist/src/compiled/@vercel/sandbox-stable/api-client/base-client.d.ts +39 -0
  24. package/dist/src/compiled/@vercel/sandbox-stable/api-client/file-writer.d.ts +66 -0
  25. package/dist/src/compiled/@vercel/sandbox-stable/api-client/index.d.ts +2 -0
  26. package/dist/src/compiled/@vercel/sandbox-stable/api-client/validators.d.ts +899 -0
  27. package/dist/src/compiled/@vercel/sandbox-stable/api-client/with-retry.d.ts +10 -0
  28. package/dist/src/compiled/@vercel/sandbox-stable/auth/error.d.ts +15 -0
  29. package/dist/src/compiled/@vercel/sandbox-stable/auth/file.d.ts +18 -0
  30. package/dist/src/compiled/@vercel/sandbox-stable/auth/index.d.ts +6 -0
  31. package/dist/src/compiled/@vercel/sandbox-stable/auth/oauth.d.ts +111 -0
  32. package/dist/src/compiled/@vercel/sandbox-stable/auth/poll-for-token.d.ts +28 -0
  33. package/dist/src/compiled/@vercel/sandbox-stable/auth/project.d.ts +40 -0
  34. package/dist/src/compiled/@vercel/sandbox-stable/command.d.ts +292 -0
  35. package/dist/src/compiled/@vercel/sandbox-stable/constants.d.ts +5 -0
  36. package/dist/src/compiled/@vercel/sandbox-stable/execution-context.d.ts +116 -0
  37. package/dist/src/compiled/@vercel/sandbox-stable/filesystem.d.ts +258 -0
  38. package/dist/src/compiled/@vercel/sandbox-stable/index.d.ts +12 -0
  39. package/dist/src/compiled/@vercel/sandbox-stable/index.js +1 -0
  40. package/dist/src/compiled/@vercel/sandbox-stable/network-policy.d.ts +169 -0
  41. package/dist/src/compiled/@vercel/sandbox-stable/proxy.d.ts +55 -0
  42. package/dist/src/compiled/@vercel/sandbox-stable/sandbox-user.d.ts +212 -0
  43. package/dist/src/compiled/@vercel/sandbox-stable/sandbox.d.ts +1216 -0
  44. package/dist/src/compiled/@vercel/sandbox-stable/session.d.ts +433 -0
  45. package/dist/src/compiled/@vercel/sandbox-stable/snapshot.d.ts +229 -0
  46. package/dist/src/compiled/@vercel/sandbox-stable/utils/get-credentials.d.ts +21 -0
  47. package/dist/src/compiled/@vercel/sandbox-stable/utils/paginator.d.ts +16 -0
  48. package/dist/src/compiled/@vercel/sandbox-stable/utils/resolveSignal.d.ts +15 -0
  49. package/dist/src/compiled/@vercel/sandbox-stable/utils/sandbox-snapshot.d.ts +11 -0
  50. package/dist/src/compiled/@vercel/sandbox-stable/utils/types.d.ts +11 -0
  51. package/dist/src/compiled/_chunks/node/{auth-BS3UoyvT.js → auth-BaNbsImr.js} +1 -1
  52. package/dist/src/compiled/_chunks/node/version-BYHw-SDY.js +1 -0
  53. package/dist/src/execution/sandbox/bindings/vercel.d.ts +2 -1
  54. package/dist/src/execution/sandbox/bindings/vercel.js +1 -1
  55. package/dist/src/internal/application/package.js +1 -1
  56. package/dist/src/packages/eve-catalog/src/index.js +1 -1
  57. package/dist/src/public/sandbox/backends/vercel.d.ts +5 -4
  58. package/dist/src/public/sandbox/backends/vercel.js +1 -1
  59. package/dist/src/public/sandbox/vercel-sandbox.d.ts +25 -1
  60. package/dist/src/public/sandbox/vercel.d.ts +2 -1
  61. package/dist/src/public/sandbox/vercel.js +1 -1
  62. package/dist/src/setup/scaffold/create/project.js +1 -1
  63. package/dist/src/setup/scaffold/create/web-template.d.ts +1 -1
  64. package/dist/src/setup/scaffold/create/web-template.js +0 -1
  65. package/dist/src/shared/sandbox-network-policy.d.ts +1 -1
  66. package/docs/reference/cli.md +10 -6
  67. package/package.json +2 -1
  68. package/dist/src/compiled/_chunks/node/version-Cztrk7z6.js +0 -1
@@ -0,0 +1,258 @@
1
+ import { Dirent, Stats } from "fs";
2
+
3
+ //#region src/filesystem.d.ts
4
+ type WriteFileData = string | Buffer | Uint8Array;
5
+ interface MkdirOptions {
6
+ recursive?: boolean;
7
+ signal?: AbortSignal;
8
+ }
9
+ interface RmOptions {
10
+ recursive?: boolean;
11
+ force?: boolean;
12
+ signal?: AbortSignal;
13
+ }
14
+ interface SandboxHandle {
15
+ readFileToBuffer(file: {
16
+ path: string;
17
+ }, opts?: {
18
+ signal?: AbortSignal;
19
+ }): Promise<Buffer | null>;
20
+ writeFiles(files: {
21
+ path: string;
22
+ content: Buffer;
23
+ }[], opts?: {
24
+ signal?: AbortSignal;
25
+ }): Promise<void>;
26
+ mkDir(path: string, opts?: {
27
+ signal?: AbortSignal;
28
+ }): Promise<void>;
29
+ runCommand(cmd: string, args?: string[], opts?: {
30
+ signal?: AbortSignal;
31
+ }): Promise<{
32
+ exitCode: number;
33
+ stdout(opts?: {
34
+ signal?: AbortSignal;
35
+ }): Promise<string>;
36
+ stderr(opts?: {
37
+ signal?: AbortSignal;
38
+ }): Promise<string>;
39
+ }>;
40
+ }
41
+ declare class FileSystem {
42
+ /** @internal */
43
+ private sandbox;
44
+ /** @internal */
45
+ constructor(sandbox: SandboxHandle);
46
+ /**
47
+ * Read the entire contents of a file.
48
+ *
49
+ * @param path - Path to the file
50
+ * @param options - Encoding or options object. If encoding is specified, returns a string; otherwise returns a Buffer.
51
+ */
52
+ readFile(path: string, options?: {
53
+ encoding?: null;
54
+ signal?: AbortSignal;
55
+ } | null): Promise<Buffer>;
56
+ readFile(path: string, options: {
57
+ encoding: BufferEncoding;
58
+ signal?: AbortSignal;
59
+ } | BufferEncoding): Promise<string>;
60
+ /**
61
+ * Write data to a file, replacing the file if it already exists.
62
+ *
63
+ * @param path - Path to the file
64
+ * @param data - The data to write
65
+ * @param options - Write options
66
+ */
67
+ writeFile(path: string, data: WriteFileData, options?: {
68
+ encoding?: BufferEncoding;
69
+ signal?: AbortSignal;
70
+ } | BufferEncoding): Promise<void>;
71
+ /**
72
+ * Append data to a file, creating the file if it does not yet exist.
73
+ *
74
+ * @param path - Path to the file
75
+ * @param data - The data to append
76
+ * @param options - Write options
77
+ */
78
+ appendFile(path: string, data: WriteFileData, options?: {
79
+ encoding?: BufferEncoding;
80
+ signal?: AbortSignal;
81
+ } | BufferEncoding): Promise<void>;
82
+ /**
83
+ * Create a directory.
84
+ *
85
+ * @param path - Path of the directory to create
86
+ * @param options - Options for directory creation
87
+ */
88
+ mkdir(path: string, options?: MkdirOptions | number): Promise<string | undefined>;
89
+ /**
90
+ * Read the contents of a directory.
91
+ *
92
+ * @param path - Path to the directory
93
+ * @param options - Options. When `withFileTypes` is true, returns `Dirent` objects.
94
+ */
95
+ readdir(path: string, options?: {
96
+ signal?: AbortSignal;
97
+ withFileTypes?: false;
98
+ }): Promise<string[]>;
99
+ readdir(path: string, options: {
100
+ signal?: AbortSignal;
101
+ withFileTypes: true;
102
+ }): Promise<Dirent[]>;
103
+ /**
104
+ * Get file status. Follows symbolic links.
105
+ *
106
+ * @param path - Path to the file
107
+ * @param options - Options
108
+ */
109
+ stat(path: string, options?: {
110
+ signal?: AbortSignal;
111
+ }): Promise<Stats>;
112
+ /**
113
+ * Get file status. Does not follow symbolic links.
114
+ *
115
+ * @param path - Path to the file
116
+ * @param options - Options
117
+ */
118
+ lstat(path: string, options?: {
119
+ signal?: AbortSignal;
120
+ }): Promise<Stats>;
121
+ /**
122
+ * Remove a file or symbolic link.
123
+ *
124
+ * @param path - Path to the file
125
+ * @param options - Options
126
+ */
127
+ unlink(path: string, options?: {
128
+ signal?: AbortSignal;
129
+ }): Promise<void>;
130
+ /**
131
+ * Remove files and directories.
132
+ *
133
+ * @param path - Path to remove
134
+ * @param options - Options
135
+ */
136
+ rm(path: string, options?: RmOptions): Promise<void>;
137
+ /**
138
+ * Remove a directory.
139
+ *
140
+ * @param path - Path to the directory
141
+ * @param options - Options
142
+ */
143
+ rmdir(path: string, options?: {
144
+ signal?: AbortSignal;
145
+ }): Promise<void>;
146
+ /**
147
+ * Rename a file or directory.
148
+ *
149
+ * @param oldPath - Current path
150
+ * @param newPath - New path
151
+ * @param options - Options
152
+ */
153
+ rename(oldPath: string, newPath: string, options?: {
154
+ signal?: AbortSignal;
155
+ }): Promise<void>;
156
+ /**
157
+ * Copy a file.
158
+ *
159
+ * @param src - Source path
160
+ * @param dest - Destination path
161
+ * @param options - Options
162
+ */
163
+ copyFile(src: string, dest: string, options?: {
164
+ signal?: AbortSignal;
165
+ }): Promise<void>;
166
+ /**
167
+ * Test whether a file exists and the user has the specified permissions.
168
+ *
169
+ * @param path - Path to the file
170
+ * @param options - Options
171
+ */
172
+ access(path: string, options?: {
173
+ signal?: AbortSignal;
174
+ }): Promise<void>;
175
+ /**
176
+ * Check if a path exists.
177
+ *
178
+ * This is a convenience method not in `node:fs/promises` but commonly needed.
179
+ *
180
+ * @param path - Path to check
181
+ * @param options - Options
182
+ */
183
+ exists(path: string, options?: {
184
+ signal?: AbortSignal;
185
+ }): Promise<boolean>;
186
+ /**
187
+ * Change file mode (permissions).
188
+ *
189
+ * @param path - Path to the file
190
+ * @param mode - File mode (e.g., 0o755 or "755")
191
+ * @param options - Options
192
+ */
193
+ chmod(path: string, mode: number | string, options?: {
194
+ signal?: AbortSignal;
195
+ }): Promise<void>;
196
+ /**
197
+ * Change file owner and group.
198
+ *
199
+ * @param path - Path to the file
200
+ * @param uid - User ID
201
+ * @param gid - Group ID
202
+ * @param options - Options
203
+ */
204
+ chown(path: string, uid: number, gid: number, options?: {
205
+ signal?: AbortSignal;
206
+ }): Promise<void>;
207
+ /**
208
+ * Create a symbolic link.
209
+ *
210
+ * @param target - The target of the symbolic link
211
+ * @param path - The path of the symbolic link to create
212
+ * @param options - Options
213
+ */
214
+ symlink(target: string, path: string, options?: {
215
+ signal?: AbortSignal;
216
+ }): Promise<void>;
217
+ /**
218
+ * Read the value of a symbolic link.
219
+ *
220
+ * @param path - Path to the symbolic link
221
+ * @param options - Options
222
+ */
223
+ readlink(path: string, options?: {
224
+ signal?: AbortSignal;
225
+ }): Promise<string>;
226
+ /**
227
+ * Resolve the real path of a file (resolving symlinks).
228
+ *
229
+ * @param path - Path to resolve
230
+ * @param options - Options
231
+ */
232
+ realpath(path: string, options?: {
233
+ signal?: AbortSignal;
234
+ }): Promise<string>;
235
+ /**
236
+ * Truncate a file to a specified length.
237
+ *
238
+ * @param path - Path to the file
239
+ * @param len - Length to truncate to (default: 0)
240
+ * @param options - Options
241
+ */
242
+ truncate(path: string, len?: number, options?: {
243
+ signal?: AbortSignal;
244
+ }): Promise<void>;
245
+ /**
246
+ * Create a unique temporary directory.
247
+ *
248
+ * @param prefix - The prefix for the temporary directory name
249
+ * @param options - Options
250
+ * @returns The path of the created temporary directory
251
+ */
252
+ mkdtemp(prefix: string, options?: {
253
+ signal?: AbortSignal;
254
+ }): Promise<string>;
255
+ }
256
+ //#endregion
257
+ export { FileSystem };
258
+ //# sourceMappingURL=filesystem.d.ts.map
@@ -0,0 +1,12 @@
1
+ import { APIError, StreamError } from "./api-client/api-error.js";
2
+ import { SnapshotTreeNodeData } from "./api-client/validators.js";
3
+ import { NetworkPolicy, NetworkPolicyKeyValueMatcher, NetworkPolicyMatch, NetworkPolicyMatcher, NetworkPolicyRule, NetworkTransformer } from "./network-policy.js";
4
+ import { Command, CommandFinished, CommandOutput, SerializedCommand, SerializedCommandFinished } from "./command.js";
5
+ import { SerializedSnapshot, Snapshot } from "./snapshot.js";
6
+ import { ExecutionContext } from "./execution-context.js";
7
+ import { Session } from "./session.js";
8
+ import { FileSystem } from "./filesystem.js";
9
+ import { SandboxUser, SandboxUserAlreadyExistsError } from "./sandbox-user.js";
10
+ import { Sandbox, SerializedSandbox } from "./sandbox.js";
11
+ import { InvalidRequestProxyHandler, ProxyHandler, ProxyMeta, defineSandboxProxy } from "./proxy.js";
12
+ export { APIError, Command, CommandFinished, type CommandOutput, type ExecutionContext, FileSystem, type InvalidRequestProxyHandler, type NetworkPolicy, type NetworkPolicyKeyValueMatcher, type NetworkPolicyMatch, type NetworkPolicyMatcher, type NetworkPolicyRule, type NetworkTransformer, type ProxyHandler, type ProxyMeta, Sandbox, SandboxUser, SandboxUserAlreadyExistsError, type SerializedCommand, type SerializedCommandFinished, type SerializedSandbox, type SerializedSnapshot, Session, Snapshot, type SnapshotTreeNodeData, StreamError, defineSandboxProxy };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,169 @@
1
+ //#region src/network-policy.d.ts
2
+ /**
3
+ * A transform applied to network requests matching a domain rule.
4
+ *
5
+ * @example
6
+ * {
7
+ * headers: { authorization: "Bearer sk-..." }
8
+ * }
9
+ */
10
+ type NetworkTransformer = {
11
+ /** Headers to set on the outgoing request. */
12
+ headers?: Record<string, string>;
13
+ };
14
+ /**
15
+ * Defines how a request value is matched.
16
+ */
17
+ type NetworkPolicyMatcher = {
18
+ /** Match the value exactly. */
19
+ exact?: string;
20
+ } | {
21
+ /** Match values that start with the provided prefix. */
22
+ startsWith?: string;
23
+ } | {
24
+ /** Match values against an RE2 regular expression. */
25
+ regex?: string;
26
+ };
27
+ /**
28
+ * Matcher for key/value request entries such as headers and query parameters.
29
+ */
30
+ type NetworkPolicyKeyValueMatcher = {
31
+ /** Matcher for the entry key. */
32
+ key?: NetworkPolicyMatcher;
33
+ /** Matcher for the entry value. */
34
+ value?: NetworkPolicyMatcher;
35
+ };
36
+ /**
37
+ * Request matcher for a network policy rule.
38
+ *
39
+ * All specified dimensions must match. Multiple methods are ORed; multiple
40
+ * header and query-string matchers are ANDed.
41
+ */
42
+ type NetworkPolicyMatch = {
43
+ /** Match on the request path. */
44
+ path?: NetworkPolicyMatcher;
45
+ /** Match on the HTTP method. */
46
+ method?: string[];
47
+ /** Match on query-string entries. */
48
+ queryString?: NetworkPolicyKeyValueMatcher[];
49
+ /** Match on request headers. */
50
+ headers?: NetworkPolicyKeyValueMatcher[];
51
+ };
52
+ /**
53
+ * A rule applied to requests matching a domain in the network policy.
54
+ */
55
+ type NetworkPolicyRule = {
56
+ /**
57
+ * Optional request matcher. When provided, transforms and forwarding rules
58
+ * only apply to requests that match every specified dimension.
59
+ */
60
+ match?: NetworkPolicyMatch;
61
+ } & ({
62
+ /**
63
+ * Transforms to apply to matching requests.
64
+ *
65
+ * `transform` cannot be used together with `forwardURL`.
66
+ */
67
+ transform: NetworkTransformer[];
68
+ forwardURL?: never;
69
+ } | {
70
+ transform?: never;
71
+ /**
72
+ * HTTPS proxy URL to forward matching requests to. Must not include query string or fragment.
73
+ *
74
+ * You can use the `defineSandboxProxy` helper from `@vercel/sandbox/proxy` to implement the proxy handler
75
+ * automatically, which handles authorization and extracts metadata about the request and sandbox.
76
+ *
77
+ * `forwardURL` cannot be used together with `transform`.
78
+ *
79
+ * @see https://vercel.com/docs/vercel-sandbox/concepts/firewall#requests-proxying
80
+ */
81
+ forwardURL: string;
82
+ });
83
+ /**
84
+ * Network policy to define network restrictions for the sandbox.
85
+ *
86
+ * - `"allow-all"`: Full internet access (default). All traffic is allowed.
87
+ * - `"deny-all"`: No internet access. All traffic is denied.
88
+ * - Object: Custom access with explicit allow/deny lists.
89
+ *
90
+ * @example
91
+ * // Full internet access (default)
92
+ * "allow-all"
93
+ *
94
+ * @example
95
+ * // No external access
96
+ * "deny-all"
97
+ *
98
+ * @example
99
+ * // Custom access with specific domains (simple list)
100
+ * // All traffic not explicitly allowed is denied.
101
+ * {
102
+ * allow: ["*.npmjs.org", "github.com"],
103
+ * subnets: {
104
+ * allow: ["10.0.0.0/8"],
105
+ * deny: ["10.1.0.0/16"]
106
+ * }
107
+ * }
108
+ *
109
+ * @example
110
+ * // Custom access with specific domains (record form)
111
+ * {
112
+ * allow: {
113
+ * "*.npmjs.org": [],
114
+ * "github.com": [],
115
+ * }
116
+ * }
117
+ *
118
+ * @example
119
+ * // Custom access with request transformers
120
+ * {
121
+ * allow: {
122
+ * "ai-gateway.vercel.sh": [
123
+ * {
124
+ * match: {
125
+ * method: ["POST"],
126
+ * path: { startsWith: "/v1/" },
127
+ * headers: [
128
+ * { key: { exact: "x-api-key" }, value: { exact: "placeholder" } }
129
+ * ]
130
+ * },
131
+ * transform: [{
132
+ * headers: { authorization: "Bearer ..." }
133
+ * }]
134
+ * }
135
+ * ],
136
+ * "*": []
137
+ * }
138
+ * }
139
+ */
140
+ type NetworkPolicy = "allow-all" | "deny-all" | {
141
+ /**
142
+ * Domains to allow traffic to.
143
+ * Use "*" prefix for wildcard matching (e.g., "*.npmjs.org").
144
+ *
145
+ * Accepts either:
146
+ * - `string[]`: A simple list of domains to allow.
147
+ * - `Record<string, NetworkPolicyRule[]>`: A map of domains to rules.
148
+ * An empty array allows traffic with no additional rules.
149
+ */
150
+ allow?: string[] | Record<string, NetworkPolicyRule[]>;
151
+ /**
152
+ * Subnet-level access control using CIDR notation.
153
+ */
154
+ subnets?: {
155
+ /**
156
+ * List of CIDRs to allow traffic to.
157
+ * Traffic to these addresses will bypass the domain allowlist.
158
+ */
159
+ allow?: string[];
160
+ /**
161
+ * List of CIDRs to deny traffic to.
162
+ * These take precedence over allowed domains and CIDRs.
163
+ */
164
+ deny?: string[];
165
+ };
166
+ };
167
+ //#endregion
168
+ export { NetworkPolicy, NetworkPolicyKeyValueMatcher, NetworkPolicyMatch, NetworkPolicyMatcher, NetworkPolicyRule, NetworkTransformer };
169
+ //# sourceMappingURL=network-policy.d.ts.map
@@ -0,0 +1,55 @@
1
+ //#region src/proxy.d.ts
2
+ interface ProxyMeta {
3
+ /**
4
+ * The host of the request as received by this proxy.
5
+ */
6
+ host: string;
7
+ /**
8
+ * The ID of the team that owns the sandbox that proxied the request.
9
+ */
10
+ teamId: string;
11
+ /**
12
+ * The ID of the project that owns the sandbox that proxied the request.
13
+ */
14
+ projectId: string;
15
+ /**
16
+ * The ID of the sandbox that proxied the request.
17
+ */
18
+ sandboxId: string;
19
+ /**
20
+ * The name of the sandbox that proxied the request, when using persistent sandboxes.
21
+ */
22
+ sandboxName: string;
23
+ }
24
+ type ProxyHandler = (request: Request, meta: ProxyMeta) => Response | Promise<Response>;
25
+ type InvalidRequestProxyHandler = (request: Request, error: Error) => Response | Promise<Response>;
26
+ /**
27
+ * Creates a Web Handler for proxied requests from Vercel Sandboxes using the network policy `forwardURL`
28
+ * option. The provided `handler` is called for each valid proxied request, with the original request
29
+ * alongside extracted metadata used to identify the source sandbox and request details.
30
+ *
31
+ * This function automatically verifies the OIDC token included in proxied requests to ensure the request
32
+ * is legitimate: if invalid, the `invalidRequestHandler` is called (by default, a 403 response is returned).
33
+ *
34
+ * @example
35
+ * ```ts
36
+ * export default {
37
+ * fetch: defineSandboxProxy(async (request, meta) => {
38
+ * // meta contains the original host & source team/project/sandbox ids
39
+ * console.log(meta)
40
+ *
41
+ * // return a custom response, or proxy upstream:
42
+ * return await fetch(request)
43
+ * }, (request, error) => {
44
+ * // optional, handle any authorization error
45
+ * return new Response("Forbidden", { status: 403 })
46
+ * })
47
+ * }
48
+ * ```
49
+ *
50
+ * @see https://vercel.com/docs/vercel-sandbox/concepts/firewall#requests-proxying
51
+ */
52
+ declare function defineSandboxProxy(handler: ProxyHandler, invalidRequestHandler?: InvalidRequestProxyHandler): (request: Request) => Promise<Response>;
53
+ //#endregion
54
+ export { InvalidRequestProxyHandler, ProxyHandler, ProxyMeta, defineSandboxProxy };
55
+ //# sourceMappingURL=proxy.d.ts.map
@@ -0,0 +1,212 @@
1
+ import { Command, CommandFinished } from "./command.js";
2
+ import { ExecutionContext } from "./execution-context.js";
3
+ import { RunCommandParams } from "./session.js";
4
+ import { Sandbox } from "./sandbox.js";
5
+
6
+ //#region src/sandbox-user.d.ts
7
+
8
+ /**
9
+ * Thrown when {@link Sandbox.createUser} is called for an existing username.
10
+ */
11
+ declare class SandboxUserAlreadyExistsError extends Error {
12
+ readonly username: string;
13
+ constructor(username: string);
14
+ }
15
+ /**
16
+ * A user context within a sandbox.
17
+ *
18
+ * All file and command operations default to running as this user.
19
+ * Created via {@link Sandbox.createUser} or {@link Sandbox.asUser}.
20
+ *
21
+ * @hideconstructor
22
+ */
23
+ declare class SandboxUser implements ExecutionContext {
24
+ /**
25
+ * The Linux username.
26
+ */
27
+ readonly username: string;
28
+ /**
29
+ * The user's home directory (e.g., `/home/alice`).
30
+ */
31
+ readonly homeDir: string;
32
+ private readonly sandbox;
33
+ /**
34
+ * Memoized lookup of this user's primary group.
35
+ * See {@link SandboxUser.primaryGroup}.
36
+ */
37
+ private primaryGroupPromise?;
38
+ constructor({
39
+ sandbox,
40
+ username
41
+ }: {
42
+ sandbox: Sandbox;
43
+ username: string;
44
+ });
45
+ /**
46
+ * Build the wrapped command args to run as this user via `sudo -u`.
47
+ *
48
+ * When `env` is provided, injects `env KEY=VAL ...` so that environment
49
+ * variables survive the `sudo -u` transition.
50
+ */
51
+ private buildUserCommand;
52
+ /**
53
+ * Resolve a path relative to this user's home directory.
54
+ * Absolute paths are returned as-is.
55
+ */
56
+ private resolvePath;
57
+ /**
58
+ * Start executing a command as this user.
59
+ *
60
+ * @param command - The command to execute.
61
+ * @param args - Arguments to pass to the command.
62
+ * @param opts - Optional parameters.
63
+ * @returns A {@link CommandFinished} result once execution is done.
64
+ */
65
+ runCommand(command: string, args?: string[], opts?: {
66
+ signal?: AbortSignal;
67
+ timeoutMs?: number;
68
+ }): Promise<CommandFinished>;
69
+ /**
70
+ * Start executing a command as this user in detached mode.
71
+ *
72
+ * @param params - The command parameters.
73
+ * @returns A {@link Command} instance for the running command.
74
+ */
75
+ runCommand(params: RunCommandParams & {
76
+ detached: true;
77
+ }): Promise<Command>;
78
+ /**
79
+ * Start executing a command as this user.
80
+ *
81
+ * @param params - The command parameters.
82
+ * @returns A {@link CommandFinished} result once execution is done.
83
+ */
84
+ runCommand(params: RunCommandParams): Promise<CommandFinished>;
85
+ /**
86
+ * Write files to this user's home directory (or absolute paths).
87
+ * Files are written via the sandbox HTTP API then chowned to this user.
88
+ *
89
+ * The HTTP API can write to user home dirs because they are group-owned
90
+ * by the sandbox's default user group with `770` permissions.
91
+ *
92
+ * @param files - Array of files with path, content, and optional mode
93
+ * @param opts - Optional parameters.
94
+ */
95
+ writeFiles(files: {
96
+ path: string;
97
+ content: string | Uint8Array;
98
+ mode?: number;
99
+ }[], opts?: {
100
+ signal?: AbortSignal;
101
+ }): Promise<void>;
102
+ /**
103
+ * Read a file from this user's context as a stream.
104
+ *
105
+ * @param file - File to read, with path and optional cwd
106
+ * @param opts - Optional parameters.
107
+ * @returns A ReadableStream of the file contents, or null if not found
108
+ */
109
+ readFile(file: {
110
+ path: string;
111
+ cwd?: string;
112
+ }, opts?: {
113
+ signal?: AbortSignal;
114
+ }): Promise<NodeJS.ReadableStream | null>;
115
+ /**
116
+ * Read a file from this user's context as a Buffer.
117
+ *
118
+ * @param file - File to read, with path and optional cwd
119
+ * @param opts - Optional parameters.
120
+ * @returns The file contents as a Buffer, or null if not found
121
+ */
122
+ readFileToBuffer(file: {
123
+ path: string;
124
+ cwd?: string;
125
+ }, opts?: {
126
+ signal?: AbortSignal;
127
+ }): Promise<Buffer | null>;
128
+ /**
129
+ * Download a file from this user's context to the local filesystem.
130
+ *
131
+ * @param src - Source file in the sandbox
132
+ * @param dst - Destination on the local machine
133
+ * @param opts - Optional parameters.
134
+ * @returns The absolute path to the written file, or null if not found
135
+ */
136
+ downloadFile(src: {
137
+ path: string;
138
+ cwd?: string;
139
+ }, dst: {
140
+ path: string;
141
+ cwd?: string;
142
+ }, opts?: {
143
+ mkdirRecursive?: boolean;
144
+ signal?: AbortSignal;
145
+ }): Promise<string | null>;
146
+ /**
147
+ * Read a file as this user and return its bytes, or null if it does not
148
+ * exist.
149
+ *
150
+ * Reads via `sudo -u <user> base64` rather than the HTTP file API: on stock
151
+ * runtimes the API runs as `vercel-sandbox` and cannot read files this user
152
+ * has kept private (e.g. mode `600`), whereas reading as the user always
153
+ * honours the user's own permissions. The payload is base64-encoded because
154
+ * the command output channel is UTF-8 only and would otherwise corrupt
155
+ * binary files.
156
+ */
157
+ private catAsUser;
158
+ /**
159
+ * Create a directory owned by this user.
160
+ *
161
+ * @param path - Path of the directory to create
162
+ * @param opts - Optional parameters.
163
+ */
164
+ mkDir(path: string, opts?: {
165
+ signal?: AbortSignal;
166
+ }): Promise<void>;
167
+ /**
168
+ * This user's primary group. Users created via {@link Sandbox.createUser}
169
+ * get a group named after them, but {@link Sandbox.asUser} accepts
170
+ * pre-existing users whose primary group can differ (e.g. system users), so
171
+ * we resolve it from the sandbox rather than assuming `<username>`.
172
+ *
173
+ * The result is memoized for the lifetime of this instance.
174
+ */
175
+ private primaryGroup;
176
+ private resolvePrimaryGroup;
177
+ /**
178
+ * Run `chown <ownership> <paths...>` as root, throwing on failure.
179
+ */
180
+ private chownOrThrow;
181
+ /**
182
+ * Run `chmod <mode> <paths...>` as root, throwing on failure.
183
+ */
184
+ private chmodOrThrow;
185
+ /**
186
+ * Given absolute leaf paths, return the directories strictly between this
187
+ * user's home directory and each leaf. The home dir itself is excluded, as
188
+ * are any paths that fall outside the home dir.
189
+ */
190
+ private ancestorDirsUnderHome;
191
+ /**
192
+ * Add this user to a group.
193
+ *
194
+ * @param groupname - Name of the group to join
195
+ * @param opts - Optional parameters.
196
+ */
197
+ addToGroup(groupname: string, opts?: {
198
+ signal?: AbortSignal;
199
+ }): Promise<void>;
200
+ /**
201
+ * Remove this user from a group.
202
+ *
203
+ * @param groupname - Name of the group to leave
204
+ * @param opts - Optional parameters.
205
+ */
206
+ removeFromGroup(groupname: string, opts?: {
207
+ signal?: AbortSignal;
208
+ }): Promise<void>;
209
+ }
210
+ //#endregion
211
+ export { SandboxUser, SandboxUserAlreadyExistsError };
212
+ //# sourceMappingURL=sandbox-user.d.ts.map