@vite-hub/sandbox 0.3.1 → 0.4.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.
- package/README.md +15 -15
- package/dist/{error-diagnostics-5QT_BjbQ.js → error-diagnostics-BNQwU9yq.js} +12 -0
- package/dist/index.js +17 -8
- package/dist/{module-types-DCeJbS9Z.d.ts → module-types-BoOZiNN4.d.ts} +35 -7
- package/dist/provider-loader-BDgDJ6bX.d.ts +24 -0
- package/dist/{provider-resolution-C6AQzuFG.js → provider-resolution-BrQfEQo0.js} +1 -1
- package/dist/{size-7AkVwGZb.js → size-DJNpXeAt.js} +1 -1
- package/dist/task/index.d.ts +14 -4
- package/dist/task/index.js +57 -44
- package/dist/task/runtime/provider-loader.d.ts +2 -18
- package/dist/task/runtime/provider-loader.js +1 -1
- package/dist/task/runtime/providers/cloudflare.d.ts +1 -1
- package/dist/task/runtime/providers/cloudflare.js +1 -1
- package/dist/task/runtime/providers/local.d.ts +8 -0
- package/dist/task/runtime/providers/local.js +15 -0
- package/dist/task/runtime/providers/vercel.d.ts +1 -1
- package/dist/task/runtime/providers/vercel.js +3 -3
- package/dist/task/runtime/state.d.ts +5 -4
- package/dist/task/runtime/state.js +9 -9
- package/dist/task/vite.d.ts +3 -1
- package/dist/task/vite.js +146 -123
- package/dist/{trusted-host-kxkpaQcs.js → trusted-host-RanFsFSB.js} +5 -12
- package/dist/trusted-host-environment-CWKJ7DD_.js +16 -0
- package/package.json +14 -9
package/README.md
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# @vite-hub/sandbox
|
|
2
2
|
|
|
3
|
-
[](https://npmx.dev/package/@vite-hub/sandbox)
|
|
4
|
+
[](https://npmx.dev/package/@vite-hub/sandbox)
|
|
5
|
+
[](https://github.com/vite-hub/vitehub/blob/main/LICENSE)
|
|
6
|
+
[](https://vitehub.dev/docs)
|
|
7
7
|
|
|
8
8
|
`@vite-hub/sandbox` owns portable execution for ViteHub. A project declares environment inputs, immutable Home files, writable Home state, and boot checks; a runtime Adapter turns that declaration into an inspectable preparation plan and opens active Sandbox sessions without exposing a provider SDK.
|
|
9
9
|
|
|
@@ -347,7 +347,7 @@ A sidecar that is still starting refuses connections. `sshLaunch` connects again
|
|
|
347
347
|
|
|
348
348
|
The launch command includes a cancellable `prepare` callback. Agent Drivers await it before starting provider probe deadlines, for both Codex and Claude. It runs a separate `/bin/true` connection check; direct process consumers can await it before starting their own deadline. OpenSSH local diagnostics are kept separate from remote stderr so a command that starts another failing SSH client is never repeated.
|
|
349
349
|
|
|
350
|
-
The `vite-hub` distribution also exposes this module as `vite-hub/sandbox/ssh`, and `vitehub sandbox serve` and `vitehub sandbox check` run the server and a Driver readiness check without a project config. See the [CLI reference](https://vitehub.dev/docs/
|
|
350
|
+
The `vite-hub` distribution also exposes this module as `vite-hub/sandbox/ssh`, and `vitehub sandbox serve` and `vitehub sandbox check` run the server and a Driver readiness check without a project config. See the [CLI reference](https://vitehub.dev/docs/cli#commands).
|
|
351
351
|
|
|
352
352
|
This transport grants arbitrary command execution as the configured user. It is not a sandbox and does not synchronize Workspace files. Server shutdown closes connections and stops supervised process groups. When a command ends, the server stops its process group. On Linux it also stops the processes that the command started outside that group, for example with `setsid`. It finds them by the `VITEHUB_SSH_COMMAND` environment variable. `close({ drainTimeoutMs })` stops new connections at once and waits up to `drainTimeoutMs` for open connections to close before it ends them, so a stopping container can let running commands finish. `connections` counts the open connections. `vitehub sandbox serve --drain-timeout <ms>` uses this on SIGTERM and SIGINT.
|
|
353
353
|
|
|
@@ -365,9 +365,9 @@ Install Sandbox, TypeScript, Vite, and the Sandbox provider used by your deploym
|
|
|
365
365
|
pnpm add @vite-hub/sandbox typescript @vercel/sandbox vite
|
|
366
366
|
```
|
|
367
367
|
|
|
368
|
-
Sandbox Task requires Node.js
|
|
368
|
+
Sandbox Task requires Node.js 24.15 or newer. The Vercel provider accepts `@vercel/sandbox` 3.9 and 4. Vercel execution also requires a Vercel project with Sandbox access. At runtime, use the project's environment or set `VERCEL_TOKEN`, `VERCEL_TEAM_ID`, and `VERCEL_PROJECT_ID`.
|
|
369
369
|
|
|
370
|
-
For Cloudflare, install `@cloudflare/sandbox` 1.x instead and use the ViteHub Cloudflare host integration so it can emit the required Container, Durable Object binding, migration, and Worker exports. Both providers run remote, potentially billed infrastructure
|
|
370
|
+
For Cloudflare, install `@cloudflare/sandbox` 1.x instead and use the ViteHub Cloudflare host integration so it can emit the required Container, Durable Object binding, migration, and Worker exports. Both providers run remote, potentially billed infrastructure. In `vite dev` on macOS, Linux, or WSL, Sandbox Tasks run as local processes on the `trusted-host` runtime, with no isolation and no provider account. Nitro's `miniflare` runner cannot run local tasks; select `node-worker`. To use a restrictive network policy in dev, opt into Vercel Sandbox with `remote: true`, or build for Cloudflare and run the output with Wrangler and Docker.
|
|
371
371
|
|
|
372
372
|
### Run one Sandbox Task
|
|
373
373
|
|
|
@@ -411,19 +411,19 @@ export default async function releaseNotes(payload: ReleaseNotesPayload = {}) {
|
|
|
411
411
|
}
|
|
412
412
|
```
|
|
413
413
|
|
|
414
|
-
Invoke the discovered name from server code. `runSandboxTask()` returns
|
|
414
|
+
Invoke the discovered name from server code. `runSandboxTask()` returns `[error, data]` and infers its payload and decoded result from the Definition. For example, a `Date` result becomes an ISO string or `null`. A registered handler with a required payload requires that argument at invocation; optional and zero-argument handlers can be invoked without it. The handler's context defaults to `{}` when omitted:
|
|
415
415
|
|
|
416
416
|
```ts
|
|
417
417
|
// src/server.ts
|
|
418
418
|
import { runSandboxTask } from "@vite-hub/sandbox/task";
|
|
419
419
|
|
|
420
|
-
const
|
|
420
|
+
const [error, notes] = await runSandboxTask("release-notes", {
|
|
421
421
|
notes: "ship it\nadd tests",
|
|
422
422
|
});
|
|
423
423
|
|
|
424
|
-
if (
|
|
424
|
+
if (error) throw error;
|
|
425
425
|
|
|
426
|
-
console.log(JSON.stringify(
|
|
426
|
+
console.log(JSON.stringify(notes));
|
|
427
427
|
```
|
|
428
428
|
|
|
429
429
|
Build through Vite so discovery and the runtime registry are generated, then run the server entry:
|
|
@@ -445,14 +445,14 @@ The Definition entrypoint does not import `@vite-hub/sandbox/task`. ViteHub call
|
|
|
445
445
|
|
|
446
446
|
- Set `cpu` (vCPUs) and `memory` (MiB) next to `driver`, such as `hubSandboxTask({ driver: "cloudflare", cpu: 1, memory: 4096 })`. They are minimums, and ViteHub picks the smallest driver size that fits both. Vercel gets `resources.vcpus`: 1 or an even number up to 32, with 2048 MiB for each vCPU. Cloudflare gets the smallest instance type from `lite` to `standard-4`, and the default is `standard-1` (1/2 vCPU, 4096 MiB). On Cloudflare the size belongs to the Container class, so it applies to every task of the app. ViteHub keeps the `instance_type` of your own `containers` entry and fails the build when it is smaller than `cpu` or `memory`. `maxInstances` sets the Cloudflare Container limit (default 12).
|
|
447
447
|
- Driver selection belongs to application or host configuration, not to a Definition. `hubSandboxTask({ driver: "vercel" })` and `hubSandboxTask({ driver: "cloudflare" })` are the direct-package forms. The `vite-hub` distribution infers the driver from its Vercel and Cloudflare hosts, and takes the same options in `vitehub({ sandboxTask: { ... } })`.
|
|
448
|
-
- `vitehub.sandboxTask.timeout` must be a positive integer no greater than `2_147_483_647`. Without it, a run stops after 5 minutes on every driver. It bounds one execution attempt after driver startup, including package preparation, staging, and execution. Queueing, Sandbox startup, and retry delays can make the complete `runSandboxTask()` call take longer. An elapsed attempt timeout sends an internal abort signal to cancellable driver operations and returns
|
|
448
|
+
- `vitehub.sandboxTask.timeout` must be a positive integer no greater than `2_147_483_647`. Without it, a run stops after 5 minutes on every driver. It bounds one execution attempt after driver startup, including package preparation, staging, and execution. Queueing, Sandbox startup, and retry delays can make the complete `runSandboxTask()` call take longer. An elapsed attempt timeout sends an internal abort signal to cancellable driver operations and returns `SANDBOX_TASK_RUN_FAILED` with `error.data.code` set to `SANDBOX_TASK_TIMEOUT` and status 504. On Vercel, the Sandbox session gets the task timeout plus 30 seconds, because its clock starts before Sandbox setup. ViteHub then ends the run at the task timeout, not the VM.
|
|
449
449
|
- Pass `signal` to `runSandboxTask()` when it belongs to a request or Agent Invocation. ViteHub forwards it to Sandbox startup and execution, cancels queued Cloudflare runs and retry backoff, and preserves the caller's abort reason. A Definition timeout remains the independent bound for each execution attempt.
|
|
450
|
-
- A failed run
|
|
451
|
-
- Vercel Sandbox sessions are closed in a `finally` block after success or failure. Cloudflare also creates and closes a unique Sandbox for each run unless you configure `sandboxId` or pass one to `runSandboxTask()`. Session cleanup failures return
|
|
450
|
+
- A failed run returns `SANDBOX_TASK_RUN_FAILED`. `error.cause` keeps the failure's code, message, and every detail for server logs. `toResponse(error)` from `@vite-hub/runtime` sends only `code`, `why`, and `fix`, so no stack or process output reaches the client. `resolveSandboxTaskRunner(name).run()` throws the same failure.
|
|
451
|
+
- Vercel Sandbox sessions are closed in a `finally` block after success or failure. Cloudflare also creates and closes a unique Sandbox for each run unless you configure `sandboxId` or pass one to `runSandboxTask()`. Session cleanup failures return an error, even after a successful handler. So do Cloudflare invocation-file cleanup failures in a Sandbox that stays open after the run. A Sandbox that ViteHub closes after the run loses its files when it closes, so ViteHub does not delete them separately.
|
|
452
452
|
- Cloudflare can retry the whole Task before its first command starts. After that, only the transport retries an individual command when a cold start proves it did not run. Handler errors do not replay the Task.
|
|
453
453
|
- An explicit Cloudflare `sandboxId` opts into a shared Sandbox identity. ViteHub deletes invocation-local files after each attempt, caches prepared projects by digest inside that Sandbox, and serializes runs with the same ID within one runtime isolate. Separate Worker isolates can still enter the Sandbox concurrently, so use external coordination when deployment-wide serialization is required. ViteHub leaves an explicitly named Sandbox for idle shutdown after every run, also after a timeout or an abort. A timeout or an abort stops only that run's command, so runs from other isolates keep their Container. `sleepAfter` sets the idle time (default `"5m"`), and `keepAlive: true` raises it to the 6 hour Cloudflare maximum. A Sandbox without an ID still closes after each run, also with `keepAlive: true`.
|
|
454
454
|
|
|
455
|
-
When `resolveSandboxTaskRunner().run()` throws, its error cause retains the original provider diagnostic. If execution and cleanup both fail, the cause chain contains an `AggregateError` with both failures. The primary error code and message stay unchanged.
|
|
455
|
+
When `resolveSandboxTaskRunner().run()` throws, its error cause retains the original provider diagnostic. If execution and cleanup both fail, the cause chain contains an `AggregateError` with both failures. The primary error code and message stay unchanged. `toResponse(error)` omits causes.
|
|
456
456
|
|
|
457
457
|
### Security and isolation
|
|
458
458
|
|
|
@@ -332,6 +332,18 @@ const sandboxTaskErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
|
332
332
|
why: ({ className, configured, requested }) => `[vitehub] The Cloudflare containers entry of class ${className} sets max_instances ${configured}, but the Sandbox Task option maxInstances is ${requested}.`,
|
|
333
333
|
fix: "Set the instance limit in one place: remove `maxInstances` from the Sandbox Task options, or remove `max_instances` from your `containers` entry."
|
|
334
334
|
},
|
|
335
|
+
SANDBOX_TASK_LOCAL_NETWORK_POLICY: {
|
|
336
|
+
why: "Local Sandbox Tasks cannot enforce the configured `networkPolicy`. Use `remote: true` on Vercel or run the Cloudflare build with Wrangler.",
|
|
337
|
+
fix: "Set `remote: true` to keep the policy on Vercel. On Cloudflare, build and run `npx wrangler dev --config .output/server/wrangler.json` with Docker to use the Container."
|
|
338
|
+
},
|
|
339
|
+
SANDBOX_TASK_LOCAL_NITRO_RUNNER: {
|
|
340
|
+
why: "Local Sandbox Tasks cannot start Node processes in Nitro's `miniflare` dev runner.",
|
|
341
|
+
fix: "Set `nitro.devServer.runner` to `node-worker`. To test Cloudflare Containers instead, build and run `npx wrangler dev --config .output/server/wrangler.json` with Docker."
|
|
342
|
+
},
|
|
343
|
+
SANDBOX_TASK_LOCAL_WINDOWS: {
|
|
344
|
+
why: "Local Sandbox Tasks require a POSIX shell and do not run on native Windows.",
|
|
345
|
+
fix: "Run the dev server in WSL, or set `remote: true` to use Vercel Sandbox. On Cloudflare, build and run `npx wrangler dev --config .output/server/wrangler.json` with Docker to use the Container."
|
|
346
|
+
},
|
|
335
347
|
SANDBOX_TASK_RENAMED_PROVIDER_KEY: {
|
|
336
348
|
why: ({ value }) => `\`sandboxTask.provider\` is ${value}. ViteHub renamed this key to \`driver\`, and it does not read \`provider\`, so the Sandbox Task would not use the driver you chose.`,
|
|
337
349
|
fix: ({ value }) => `Set \`sandboxTask: { driver: ${value} }\`, or run \`npx @vite-hub/codemods driver-key\` to rename it in every config file.`
|
package/dist/index.js
CHANGED
|
@@ -12,6 +12,9 @@ const reservedRuntimeNames = /* @__PURE__ */ new Set([
|
|
|
12
12
|
"trusted-host",
|
|
13
13
|
"vercel"
|
|
14
14
|
]);
|
|
15
|
+
function withoutKind({ kind: _kind, ...options }) {
|
|
16
|
+
return options;
|
|
17
|
+
}
|
|
15
18
|
async function resolveSandboxRuntime(value) {
|
|
16
19
|
if (isSandboxRuntime(value)) {
|
|
17
20
|
if (reservedRuntimeNames.has(value.name) && !isBuiltInSandboxRuntime(value)) throw sandboxErrorDiagnostics.SANDBOX_R0030({ message: `[vitehub] Custom Sandbox runtimes cannot use the reserved name "${value.name}". Select the built-in runtime by value instead.` });
|
|
@@ -23,7 +26,7 @@ async function resolveSandboxRuntime(value) {
|
|
|
23
26
|
return createCrabboxRuntime();
|
|
24
27
|
}
|
|
25
28
|
if (value === "trusted-host") {
|
|
26
|
-
const { createTrustedHostRuntime } = await import("./trusted-host-
|
|
29
|
+
const { createTrustedHostRuntime } = await import("./trusted-host-RanFsFSB.js").then((n) => n.n);
|
|
27
30
|
return createTrustedHostRuntime();
|
|
28
31
|
}
|
|
29
32
|
if (value === "vercel") {
|
|
@@ -33,24 +36,30 @@ async function resolveSandboxRuntime(value) {
|
|
|
33
36
|
throw sandboxErrorDiagnostics.SANDBOX_R0031({ message: `[vitehub] Unknown Sandbox runtime "${value}". Expected "crabbox", "trusted-host", "vercel", a tagged built-in configuration, or a custom runtime.` });
|
|
34
37
|
}
|
|
35
38
|
if (!value || typeof value !== "object" || Array.isArray(value)) throw sandboxErrorDiagnostics.SANDBOX_R0032({ message: "[vitehub] Sandbox requires an explicit built-in runtime value or custom runtime object." });
|
|
36
|
-
const
|
|
37
|
-
|
|
39
|
+
const config = value;
|
|
40
|
+
const kind = config.kind;
|
|
41
|
+
if (config.kind === "crabbox") {
|
|
42
|
+
const options = withoutKind(config);
|
|
38
43
|
const { createCrabboxRuntime } = await import("./crabbox-sbV3Zjuo.js");
|
|
39
44
|
return createCrabboxRuntime(options);
|
|
40
45
|
}
|
|
41
|
-
if (kind === "trusted-host") {
|
|
42
|
-
const
|
|
46
|
+
if (config.kind === "trusted-host") {
|
|
47
|
+
const options = withoutKind(config);
|
|
48
|
+
const { createTrustedHostRuntime } = await import("./trusted-host-RanFsFSB.js").then((n) => n.n);
|
|
43
49
|
return createTrustedHostRuntime(options);
|
|
44
50
|
}
|
|
45
|
-
if (kind === "cloudflare") {
|
|
51
|
+
if (config.kind === "cloudflare") {
|
|
52
|
+
const options = withoutKind(config);
|
|
46
53
|
const { createCloudflareRuntime } = await import("./cloudflare-Cog_r2Me.js").then((n) => n.t);
|
|
47
54
|
return createCloudflareRuntime(options);
|
|
48
55
|
}
|
|
49
|
-
if (kind === "vercel") {
|
|
56
|
+
if (config.kind === "vercel") {
|
|
57
|
+
const options = withoutKind(config);
|
|
50
58
|
const { createVercelRuntime } = await import("./vercel-BGGrNpza.js").then((n) => n.r);
|
|
51
59
|
return createVercelRuntime(options);
|
|
52
60
|
}
|
|
53
|
-
if (kind === "container") {
|
|
61
|
+
if (config.kind === "container") {
|
|
62
|
+
const options = withoutKind(config);
|
|
54
63
|
const { createContainerRuntime } = await import("./container-CqfD8yuE.js");
|
|
55
64
|
return createContainerRuntime(options);
|
|
56
65
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Q as VercelSandboxSource, X as VercelSandboxNetworkPolicy, st as SandboxNetworkPolicy } from "./index-DsoQAUb7.js";
|
|
2
|
+
import { ViteHubError } from "@vite-hub/runtime";
|
|
2
3
|
//#region src/task/project.d.ts
|
|
3
4
|
type SandboxTaskPackageManager = 'bun' | 'npm' | 'pnpm' | 'yarn';
|
|
4
5
|
interface SandboxTaskProjectFile {
|
|
@@ -18,6 +19,24 @@ interface SandboxTaskProject {
|
|
|
18
19
|
packagePath: string;
|
|
19
20
|
}
|
|
20
21
|
//#endregion
|
|
22
|
+
//#region src/task/runtime/result.d.ts
|
|
23
|
+
declare const sandboxTaskRunErrors: import("@vite-hub/runtime").ErrorCatalog<{
|
|
24
|
+
readonly SANDBOX_TASK_RUN_FAILED: {
|
|
25
|
+
readonly why: ({ name, code }: {
|
|
26
|
+
name: string;
|
|
27
|
+
code: string;
|
|
28
|
+
}) => string;
|
|
29
|
+
readonly fix: "Read `error.cause` for the message, `details`, and process output of the failure. `error.data.code` is its code, such as `SANDBOX_TASK_TIMEOUT`.";
|
|
30
|
+
readonly data: ({ name, code }: {
|
|
31
|
+
name: string;
|
|
32
|
+
code: string;
|
|
33
|
+
}) => {
|
|
34
|
+
name: string;
|
|
35
|
+
code: string;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
}>;
|
|
39
|
+
//#endregion
|
|
21
40
|
//#region src/task/size.d.ts
|
|
22
41
|
/** The size of the machine that runs every Sandbox Task. Both values are minimums. */
|
|
23
42
|
interface SandboxTaskSizeOptions {
|
|
@@ -34,7 +53,14 @@ interface CloudflareSandboxTaskOptions {
|
|
|
34
53
|
keepAlive?: boolean;
|
|
35
54
|
normalizeId?: boolean;
|
|
36
55
|
}
|
|
37
|
-
interface
|
|
56
|
+
interface SandboxTaskDevOptions {
|
|
57
|
+
/**
|
|
58
|
+
* `vite dev` runs Sandbox Tasks as processes on this machine, with no isolation and no provider account.
|
|
59
|
+
* Set `true` to use the host's Sandbox in `vite dev` too.
|
|
60
|
+
*/
|
|
61
|
+
remote?: boolean;
|
|
62
|
+
}
|
|
63
|
+
interface VercelSandboxTaskDriverOptions extends SandboxTaskSizeOptions, SandboxTaskDevOptions {
|
|
38
64
|
driver: 'vercel';
|
|
39
65
|
runtime?: string;
|
|
40
66
|
ports?: number[];
|
|
@@ -45,7 +71,7 @@ interface VercelSandboxTaskDriverOptions extends SandboxTaskSizeOptions {
|
|
|
45
71
|
teamId?: string;
|
|
46
72
|
projectId?: string;
|
|
47
73
|
}
|
|
48
|
-
interface CloudflareSandboxTaskDefinitionDriverOptions extends SandboxTaskSizeOptions {
|
|
74
|
+
interface CloudflareSandboxTaskDefinitionDriverOptions extends SandboxTaskSizeOptions, SandboxTaskDevOptions {
|
|
49
75
|
driver: 'cloudflare';
|
|
50
76
|
/** Maximum number of Containers that run at once. Defaults to 12. */
|
|
51
77
|
maxInstances?: number;
|
|
@@ -64,7 +90,7 @@ type SandboxTaskDefinitionDriverOptions = VercelSandboxTaskDriverOptions | Cloud
|
|
|
64
90
|
type AgentSandboxTaskConfig = SandboxTaskDefinitionDriverOptions | ({
|
|
65
91
|
driver?: undefined;
|
|
66
92
|
name?: string;
|
|
67
|
-
} & SandboxTaskSizeOptions);
|
|
93
|
+
} & SandboxTaskSizeOptions & SandboxTaskDevOptions);
|
|
68
94
|
interface SandboxTaskDefinitionBundle {
|
|
69
95
|
entry: string;
|
|
70
96
|
execution?: 'definition' | 'module';
|
|
@@ -102,9 +128,11 @@ interface SandboxTaskDefinition<TPayload = unknown, TResult = unknown> {
|
|
|
102
128
|
type SandboxTaskDefinitionFromHandler<THandler extends (...args: any[]) => any> = SandboxTaskDefinition<SandboxTaskDefinitionPayload<THandler>, SandboxTaskDefinitionResult<THandler>> & {
|
|
103
129
|
handler: THandler;
|
|
104
130
|
};
|
|
105
|
-
/**
|
|
106
|
-
*
|
|
107
|
-
|
|
131
|
+
/**
|
|
132
|
+
* What `runSandboxTask()` returns: `[error, data]`. `data` is the decoded handler result. A failed run returns
|
|
133
|
+
* `SANDBOX_TASK_RUN_FAILED`, with the failure in `error.cause`.
|
|
134
|
+
*/
|
|
135
|
+
type SandboxTaskRunResult<TResult = unknown> = [error: ReturnType<typeof sandboxTaskRunErrors.SANDBOX_TASK_RUN_FAILED>, data: undefined] | [error: undefined, data: TResult];
|
|
108
136
|
declare function getSandboxTaskFeatureDriver(config?: AgentSandboxTaskConfig | false): SandboxTaskDefinitionDriverOptions | undefined;
|
|
109
137
|
//#endregion
|
|
110
|
-
export {
|
|
138
|
+
export { VercelSandboxTaskDriverOptions as _, SandboxTaskDefinitionBundle as a, SandboxTaskDefinitionHandler as c, SandboxTaskDevOptions as d, SandboxTaskDriver as f, SandboxTaskRunResult as g, SandboxTaskRunArguments as h, SandboxTaskDefinition as i, SandboxTaskDefinitionInput as l, SandboxTaskProjectOptions as m, CloudflareSandboxTaskDefinitionDriverOptions as n, SandboxTaskDefinitionDriverOptions as o, SandboxTaskExecutionOptions as p, CloudflareSandboxTaskOptions as r, SandboxTaskDefinitionFromHandler as s, AgentSandboxTaskConfig as t, SandboxTaskDefinitionOptions as u, getSandboxTaskFeatureDriver as v, SandboxTaskSizeOptions as y };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { l as Sandbox } from "./index-DsoQAUb7.js";
|
|
2
|
+
import { f as SandboxTaskDriver, o as SandboxTaskDefinitionDriverOptions, u as SandboxTaskDefinitionOptions } from "./module-types-BoOZiNN4.js";
|
|
3
|
+
import { ExecutionAuthority } from "@vite-hub/runtime";
|
|
4
|
+
//#region src/task/runtime/task-sandbox.d.ts
|
|
5
|
+
/** `local` runs a Sandbox Task as a process on this machine, which only `vite dev` does. */
|
|
6
|
+
type SandboxTaskExecutionProvider = 'cloudflare' | 'vercel' | 'local';
|
|
7
|
+
//#endregion
|
|
8
|
+
//#region src/task/runtime/provider-loader.d.ts
|
|
9
|
+
interface ResolvedTaskSandbox {
|
|
10
|
+
provider: SandboxTaskExecutionProvider;
|
|
11
|
+
resolveSandbox: (requirements: readonly string[]) => Promise<Sandbox>;
|
|
12
|
+
sandboxId?: string;
|
|
13
|
+
}
|
|
14
|
+
interface SandboxTaskRuntimeProvider {
|
|
15
|
+
resolveTaskSandbox: (options: {
|
|
16
|
+
local: SandboxTaskDefinitionOptions;
|
|
17
|
+
provider: SandboxTaskDefinitionDriverOptions & {
|
|
18
|
+
driver: SandboxTaskDriver;
|
|
19
|
+
};
|
|
20
|
+
} | any) => Promise<ResolvedTaskSandbox>;
|
|
21
|
+
}
|
|
22
|
+
declare function loadSandboxTaskRuntimeProvider(provider: SandboxTaskDriver): Promise<SandboxTaskRuntimeProvider>;
|
|
23
|
+
//#endregion
|
|
24
|
+
export { SandboxTaskRuntimeProvider as n, loadSandboxTaskRuntimeProvider as r, ResolvedTaskSandbox as t };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as sandboxTaskErrorDiagnostics } from "./error-diagnostics-
|
|
1
|
+
import { t as sandboxTaskErrorDiagnostics } from "./error-diagnostics-BNQwU9yq.js";
|
|
2
2
|
import { t as getActiveCloudflareEnv } from "./cloudflare-env-lookup-DzI6Xv1Y.js";
|
|
3
3
|
import { ViteHubError, getViteHubErrorShape } from "@vite-hub/runtime";
|
|
4
4
|
//#region src/task/sandbox-task/errors.ts
|
package/dist/task/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { _ as
|
|
1
|
+
import { _ as VercelSandboxTaskDriverOptions, a as SandboxTaskDefinitionBundle, c as SandboxTaskDefinitionHandler, d as SandboxTaskDevOptions, f as SandboxTaskDriver, g as SandboxTaskRunResult, h as SandboxTaskRunArguments, i as SandboxTaskDefinition, l as SandboxTaskDefinitionInput, m as SandboxTaskProjectOptions, n as CloudflareSandboxTaskDefinitionDriverOptions, o as SandboxTaskDefinitionDriverOptions, p as SandboxTaskExecutionOptions, r as CloudflareSandboxTaskOptions, s as SandboxTaskDefinitionFromHandler, t as AgentSandboxTaskConfig, u as SandboxTaskDefinitionOptions, v as getSandboxTaskFeatureDriver, y as SandboxTaskSizeOptions } from "../module-types-BoOZiNN4.js";
|
|
2
2
|
import { ExecutionAuthority, ViteHubContext } from "@vite-hub/runtime";
|
|
3
|
+
import { Buffer } from "node:buffer";
|
|
3
4
|
import { SandboxTaskDefinitionModules } from "#vitehub-sandbox-task-registry";
|
|
4
5
|
//#region src/task/runtime/registry.d.ts
|
|
5
6
|
export declare function defineSandboxTask<THandler extends (...args: any[]) => any>(input: SandboxTaskDefinitionInput<Parameters<THandler>[0], Awaited<ReturnType<THandler>>> & {
|
|
@@ -46,10 +47,19 @@ type SandboxTaskPayload<TDefinition> = TDefinition extends {
|
|
|
46
47
|
} ? TPayload : unknown;
|
|
47
48
|
type SandboxTaskResult<TDefinition> = TDefinition extends {
|
|
48
49
|
result: infer TResult;
|
|
49
|
-
} ? TResult : unknown;
|
|
50
|
+
} ? DecodedSandboxValue<TResult> : unknown;
|
|
51
|
+
/** Model the result walk in entry-script.injected.ts, not the handler's remote object. */
|
|
52
|
+
type DecodedSandboxValue<TValue, TApplyToJSON extends boolean = true> = TValue extends Response ? Response : TValue extends Blob ? Blob : TValue extends Buffer ? Buffer : TValue extends Uint8Array ? Uint8Array : TApplyToJSON extends false ? DecodedSandboxJson<TValue> : TValue extends {
|
|
53
|
+
toJSON(key: string): infer TSerialized;
|
|
54
|
+
} ? DecodedSandboxValue<TSerialized, false> | (TValue extends Date ? null : never) : DecodedSandboxJson<TValue>;
|
|
55
|
+
type DecodedSandboxJson<TValue> = TValue extends string | number | boolean | null ? TValue : TValue extends InstanceType<StringConstructor> ? string : TValue extends InstanceType<NumberConstructor> ? number : TValue extends InstanceType<BooleanConstructor> ? boolean : TValue extends readonly unknown[] ? { [TIndex in keyof TValue]: DecodedSandboxValue<TValue[TIndex]>; } : TValue extends ((...args: never[]) => unknown) | undefined | bigint | symbol ? never : TValue extends object ? { [TKey in keyof TValue as TKey extends symbol ? never : TValue[TKey] extends ((...args: never[]) => unknown) ? never : TKey]: DecodedSandboxValue<TValue[TKey]>; } : TValue;
|
|
50
56
|
//#endregion
|
|
51
57
|
//#region src/task/runtime/public.d.ts
|
|
52
|
-
|
|
58
|
+
/**
|
|
59
|
+
* Run a Sandbox Task by its name. `data` is the decoded handler result, such as a JSON value or a native `Response`.
|
|
60
|
+
* A failed run returns `SANDBOX_TASK_RUN_FAILED`, and `toResponse(error)` answers with its status.
|
|
61
|
+
*/
|
|
62
|
+
export declare function runSandboxTask<const TName extends string>(name: TName, ...args: SandboxTaskRunArguments<TName extends SandboxTaskDefinitionName ? SandboxTaskPayload<SandboxTaskRegistryDefinition<TName>> : unknown>): Promise<SandboxTaskRunResult<TName extends SandboxTaskDefinitionName ? SandboxTaskResult<SandboxTaskRegistryDefinition<TName>> : unknown>>;
|
|
53
63
|
//#endregion
|
|
54
64
|
//#region src/task/runtime/provider-resolution.d.ts
|
|
55
65
|
export declare function unsupportedHostedSandboxTaskProviderError(provider: unknown): Error;
|
|
@@ -66,4 +76,4 @@ type ResolvedSandboxTaskRunner<TPayload, TResult> = Omit<SandboxTaskRunner, 'run
|
|
|
66
76
|
export declare function resolveSandboxTaskRunner<const TName extends SandboxTaskDefinitionName>(name: TName): Promise<ResolvedSandboxTaskRunner<SandboxTaskPayload<SandboxTaskRegistryDefinition<TName>>, SandboxTaskResult<SandboxTaskRegistryDefinition<TName>>>>;
|
|
67
77
|
export declare function resolveSandboxTaskRunner<TPayload = unknown, TResult = unknown>(name?: string): Promise<ResolvedSandboxTaskRunner<TPayload, TResult>>;
|
|
68
78
|
//#endregion
|
|
69
|
-
export type { AgentSandboxTaskConfig, CloudflareSandboxTaskDefinitionDriverOptions, CloudflareSandboxTaskOptions, SandboxTaskDefinition, SandboxTaskDefinitionBundle, SandboxTaskDefinitionDriverOptions, SandboxTaskDefinitionFromHandler, SandboxTaskDefinitionHandler, SandboxTaskDefinitionInput, SandboxTaskDefinitionOptions, SandboxTaskDriver, SandboxTaskExecutionOptions, SandboxTaskProjectOptions, SandboxTaskRunArguments, SandboxTaskRunResult, SandboxTaskRunner, SandboxTaskSizeOptions, VercelSandboxTaskDriverOptions, getSandboxTaskFeatureDriver };
|
|
79
|
+
export type { AgentSandboxTaskConfig, CloudflareSandboxTaskDefinitionDriverOptions, CloudflareSandboxTaskOptions, SandboxTaskDefinition, SandboxTaskDefinitionBundle, SandboxTaskDefinitionDriverOptions, SandboxTaskDefinitionFromHandler, SandboxTaskDefinitionHandler, SandboxTaskDefinitionInput, SandboxTaskDefinitionOptions, SandboxTaskDevOptions, SandboxTaskDriver, SandboxTaskExecutionOptions, SandboxTaskProjectOptions, SandboxTaskRunArguments, SandboxTaskRunResult, SandboxTaskRunner, SandboxTaskSizeOptions, VercelSandboxTaskDriverOptions, getSandboxTaskFeatureDriver };
|
package/dist/task/index.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { n as cloudflareRetryDelays, r as readCloudflareFailure, t as canRetryCloudflareRequest } from "../cloudflare-failure-CFQhalfh.js";
|
|
2
|
-
import { t as sandboxTaskErrorDiagnostics } from "../error-diagnostics-
|
|
3
|
-
import { a as resolveTaskSandbox, c as isSandboxTaskError, i as resolveRuntimeProvider, l as sandboxTaskError, n as assertSandboxTaskDefinitionOptions, o as unsupportedHostedSandboxTaskProviderError, r as createCloudflareExecutionSandboxId, s as withSandboxTaskProvider } from "../provider-resolution-
|
|
4
|
-
import {
|
|
2
|
+
import { t as sandboxTaskErrorDiagnostics } from "../error-diagnostics-BNQwU9yq.js";
|
|
3
|
+
import { a as resolveTaskSandbox, c as isSandboxTaskError, i as resolveRuntimeProvider, l as sandboxTaskError, n as assertSandboxTaskDefinitionOptions, o as unsupportedHostedSandboxTaskProviderError, r as createCloudflareExecutionSandboxId, s as withSandboxTaskProvider } from "../provider-resolution-BrQfEQo0.js";
|
|
4
|
+
import { t as isTrustedHostReservedCommandEnvironmentKey } from "../trusted-host-environment-CWKJ7DD_.js";
|
|
5
|
+
import { getSandboxTaskRuntimeConfig, getSandboxTaskRuntimeLocalProvider, getSandboxTaskRuntimeRegistry } from "./runtime/state.js";
|
|
5
6
|
import { t as getSandboxTaskFeatureDriver } from "../module-types-B0LQ5H2S.js";
|
|
6
|
-
import { deserializeResponse, getViteHubErrorShape, isSerializedResponse
|
|
7
|
+
import { defineErrors, deserializeResponse, getViteHubErrorShape, isSerializedResponse } from "@vite-hub/runtime";
|
|
7
8
|
import { types } from "node:util";
|
|
8
9
|
import { getStandardContext } from "@vite-hub/runtime/internal/h3";
|
|
9
10
|
import { dirname } from "pathe";
|
|
@@ -363,7 +364,7 @@ function sandboxTaskCode(code) {
|
|
|
363
364
|
//#endregion
|
|
364
365
|
//#region src/task/runtime/entry-script.injected.ts
|
|
365
366
|
const EXEC_STDIO_OUTPUT_MARKER = "__VITEHUB_OUTPUT__";
|
|
366
|
-
function createEntrySource(definitionPath, execution = "definition") {
|
|
367
|
+
function createEntrySource(definitionPath, execution = "definition", env) {
|
|
367
368
|
const invocation = execution === "module" ? [
|
|
368
369
|
` const mod = await import(pathToFileURL(${JSON.stringify(definitionPath)}).href)`,
|
|
369
370
|
` const exported = await mod.default`,
|
|
@@ -645,6 +646,7 @@ function createEntrySource(definitionPath, execution = "definition") {
|
|
|
645
646
|
`export async function main(argv = process.argv.slice(2)) {`,
|
|
646
647
|
` const [inputPath, outputPath] = argv`,
|
|
647
648
|
` try {`,
|
|
649
|
+
...Object.entries(env ?? {}).map(([name, value]) => ` process.env[${JSON.stringify(name)}] = ${JSON.stringify(value)}`),
|
|
648
650
|
` const raw = await readFile(inputPath, 'utf8')`,
|
|
649
651
|
` const input = await reviveValue(JSON.parse(raw || '{}'), inputPath + '.files', 'input')`,
|
|
650
652
|
` input.context ??= {}`,
|
|
@@ -675,9 +677,9 @@ function normalizeSandboxTaskDefinitionBundle(source) {
|
|
|
675
677
|
};
|
|
676
678
|
return source;
|
|
677
679
|
}
|
|
678
|
-
function createExecutionFiles(definitionName) {
|
|
680
|
+
function createExecutionFiles(definitionName, tempDir = "/tmp") {
|
|
679
681
|
const nonce = `${Date.now()}-${Math.random().toString(36).slice(2, 10)}`;
|
|
680
|
-
const baseDir =
|
|
682
|
+
const baseDir = `${tempDir}/vitehub-sandbox-task/${definitionName.replace(/[^a-z0-9/_-]/gi, "_")}-${nonce}`;
|
|
681
683
|
return {
|
|
682
684
|
baseDir,
|
|
683
685
|
entryPath: `${baseDir}/entry.mjs`,
|
|
@@ -744,13 +746,13 @@ async function prepareSandboxTaskDefinition(sandbox, bundle, baseDir, options) {
|
|
|
744
746
|
cwd: baseDir
|
|
745
747
|
};
|
|
746
748
|
}
|
|
747
|
-
const projectDir =
|
|
749
|
+
const projectDir = `${sandbox.tempDir}/vitehub-sandbox-task/projects/${project.digest}`;
|
|
748
750
|
const marker = `${projectDir}/.vitehub/prepared`;
|
|
749
751
|
const prepared = {
|
|
750
752
|
directory: projectDir,
|
|
751
753
|
cwd: resolveSandboxTaskModulePath(projectDir, project.packagePath)
|
|
752
754
|
};
|
|
753
|
-
await sandbox.mkdir(
|
|
755
|
+
await sandbox.mkdir(`${sandbox.tempDir}/vitehub-sandbox-task/projects`, {
|
|
754
756
|
recursive: true,
|
|
755
757
|
signal: options.signal
|
|
756
758
|
});
|
|
@@ -1012,7 +1014,7 @@ function toJson(value, label) {
|
|
|
1012
1014
|
}
|
|
1013
1015
|
async function executeSandboxTaskDefinitionOnce(sandbox, definitionName, definitionOptions, source, payload, context, signal, lifecycle, deadline) {
|
|
1014
1016
|
const bundle = normalizeSandboxTaskDefinitionBundle(source);
|
|
1015
|
-
const files = createExecutionFiles(definitionName);
|
|
1017
|
+
const files = createExecutionFiles(definitionName, sandbox.tempDir);
|
|
1016
1018
|
let failure;
|
|
1017
1019
|
const throwIfAborted = () => {
|
|
1018
1020
|
if (signal?.aborted) throw signal.reason ?? new DOMException("The Sandbox invocation was aborted.", "AbortError");
|
|
@@ -1037,10 +1039,22 @@ async function executeSandboxTaskDefinitionOnce(sandbox, definitionName, definit
|
|
|
1037
1039
|
context
|
|
1038
1040
|
}, files.inputAssetsDir, "payload/context", signal), "payload/context");
|
|
1039
1041
|
const definitionPath = resolveSandboxTaskModulePath(prepared.directory, bundle.entry);
|
|
1042
|
+
const local = sandbox.provider === "local";
|
|
1043
|
+
let env = definitionOptions?.env;
|
|
1044
|
+
let entryEnvironment;
|
|
1045
|
+
if (local && env) {
|
|
1046
|
+
const entries = Object.entries(env);
|
|
1047
|
+
entryEnvironment = Object.fromEntries(entries.filter(([name]) => isTrustedHostReservedCommandEnvironmentKey(name)));
|
|
1048
|
+
env = Object.fromEntries(entries.filter(([name]) => !isTrustedHostReservedCommandEnvironmentKey(name)));
|
|
1049
|
+
}
|
|
1040
1050
|
throwIfAborted();
|
|
1041
|
-
await Promise.all([sandbox.writeFile(files.entryPath, createEntrySource(definitionPath, bundle.execution), { signal }), sandbox.writeFile(files.inputPath, inputJson, { signal })]);
|
|
1051
|
+
await Promise.all([sandbox.writeFile(files.entryPath, createEntrySource(definitionPath, bundle.execution, entryEnvironment), { signal }), sandbox.writeFile(files.inputPath, inputJson, { signal })]);
|
|
1042
1052
|
throwIfAborted();
|
|
1043
|
-
const execArgs = [
|
|
1053
|
+
const execArgs = local ? [
|
|
1054
|
+
files.entryPath,
|
|
1055
|
+
files.inputPath,
|
|
1056
|
+
files.outputPath
|
|
1057
|
+
] : [
|
|
1044
1058
|
"-e",
|
|
1045
1059
|
"import(process.argv[1])",
|
|
1046
1060
|
files.entryPath,
|
|
@@ -1053,7 +1067,7 @@ async function executeSandboxTaskDefinitionOnce(sandbox, definitionName, definit
|
|
|
1053
1067
|
lifecycle?.onCommandStart?.();
|
|
1054
1068
|
execution = await sandbox.exec("node", execArgs, {
|
|
1055
1069
|
cwd: prepared.cwd,
|
|
1056
|
-
env
|
|
1070
|
+
env,
|
|
1057
1071
|
signal,
|
|
1058
1072
|
timeout: definitionOptions?.timeout
|
|
1059
1073
|
});
|
|
@@ -1179,6 +1193,7 @@ function createTaskSandbox(session, provider, closesAfterRun) {
|
|
|
1179
1193
|
id: session.id,
|
|
1180
1194
|
files: session.files,
|
|
1181
1195
|
provider,
|
|
1196
|
+
tempDir: provider === "local" ? `${session.cwd}/tmp` : "/tmp",
|
|
1182
1197
|
closesAfterRun,
|
|
1183
1198
|
async close() {
|
|
1184
1199
|
await session.close();
|
|
@@ -1204,10 +1219,18 @@ function createTaskSandbox(session, provider, closesAfterRun) {
|
|
|
1204
1219
|
}
|
|
1205
1220
|
//#endregion
|
|
1206
1221
|
//#region src/task/runtime/result.ts
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
}
|
|
1222
|
+
const sandboxTaskRunErrors = /*#__PURE__*/ defineErrors({
|
|
1223
|
+
docs: "https://vitehub.dev/docs/sandbox/diagnostics",
|
|
1224
|
+
codes: { SANDBOX_TASK_RUN_FAILED: {
|
|
1225
|
+
why: ({ name, code }) => `Sandbox Task ${JSON.stringify(name)} failed with ${code}.`,
|
|
1226
|
+
fix: "Read `error.cause` for the message, `details`, and process output of the failure. `error.data.code` is its code, such as `SANDBOX_TASK_TIMEOUT`.",
|
|
1227
|
+
data: ({ name, code }) => ({
|
|
1228
|
+
name,
|
|
1229
|
+
code
|
|
1230
|
+
})
|
|
1231
|
+
} }
|
|
1232
|
+
});
|
|
1233
|
+
/** Preserve an explicit HTTP status or map the underlying diagnostic code. */
|
|
1211
1234
|
function statusFor(error) {
|
|
1212
1235
|
const status = error.details?.httpStatus;
|
|
1213
1236
|
if (Number.isInteger(status) && Number(status) >= 400 && Number(status) <= 599) return Number(status);
|
|
@@ -1216,32 +1239,16 @@ function statusFor(error) {
|
|
|
1216
1239
|
if (error.code.includes("VALIDATION")) return 400;
|
|
1217
1240
|
return 500;
|
|
1218
1241
|
}
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
"output",
|
|
1224
|
-
"outputPreview",
|
|
1225
|
-
"stack",
|
|
1226
|
-
"stderr",
|
|
1227
|
-
"stderrPreview",
|
|
1228
|
-
"stdout",
|
|
1229
|
-
"stdoutPreview"
|
|
1230
|
-
]);
|
|
1231
|
-
function publicDetails(details, development) {
|
|
1232
|
-
if (development || !details) return details;
|
|
1233
|
-
return Object.fromEntries(Object.entries(details).filter(([key]) => !developmentOnlyDetails.has(key)));
|
|
1234
|
-
}
|
|
1235
|
-
/** Outside `vite dev`, the body keeps the code, message, and details without stack or process output. */
|
|
1236
|
-
function err(error, development = false) {
|
|
1237
|
-
const body = JSON.stringify({ error: {
|
|
1242
|
+
/** The error that `runSandboxTask()` returns. The failure stays in `cause`, so `toResponse(error)` sends no process output. */
|
|
1243
|
+
function runFailed(name, error) {
|
|
1244
|
+
const failure = sandboxTaskRunErrors.SANDBOX_TASK_RUN_FAILED({
|
|
1245
|
+
name,
|
|
1238
1246
|
code: error.code,
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
headers: { "content-type": "application/json; charset=utf-8" }
|
|
1247
|
+
cause: error
|
|
1248
|
+
});
|
|
1249
|
+
return Object.defineProperty(failure, "status", {
|
|
1250
|
+
configurable: true,
|
|
1251
|
+
value: statusFor(error)
|
|
1245
1252
|
});
|
|
1246
1253
|
}
|
|
1247
1254
|
//#endregion
|
|
@@ -1318,6 +1325,12 @@ function hasValidSandboxTaskBundle(definition) {
|
|
|
1318
1325
|
}
|
|
1319
1326
|
async function resolveSandboxTaskProvider(sandboxTaskConfig, definition) {
|
|
1320
1327
|
assertSandboxTaskDefinitionOptions(definition.options ?? {});
|
|
1328
|
+
const local = getSandboxTaskRuntimeLocalProvider();
|
|
1329
|
+
if (local && !(sandboxTaskConfig && sandboxTaskConfig.remote)) {
|
|
1330
|
+
const policy = sandboxTaskConfig && "networkPolicy" in sandboxTaskConfig ? sandboxTaskConfig.networkPolicy : void 0;
|
|
1331
|
+
if (policy !== void 0 && policy !== "allow-all") throw sandboxTaskErrorDiagnostics.SANDBOX_TASK_LOCAL_NETWORK_POLICY();
|
|
1332
|
+
return await local();
|
|
1333
|
+
}
|
|
1321
1334
|
const config = getSandboxTaskFeatureDriver(sandboxTaskConfig);
|
|
1322
1335
|
const provider = resolveRuntimeProvider(config);
|
|
1323
1336
|
return await resolveTaskSandbox(provider, withSandboxTaskProvider(provider, config), definition.options ?? {});
|
|
@@ -1399,10 +1412,10 @@ async function resolveSandboxTaskRunner(name) {
|
|
|
1399
1412
|
async function runSandboxTaskRuntime(name, payload, options) {
|
|
1400
1413
|
try {
|
|
1401
1414
|
options?.signal?.throwIfAborted();
|
|
1402
|
-
return
|
|
1415
|
+
return [void 0, await (await resolveSandboxTaskRunner(name)).run(payload, options)];
|
|
1403
1416
|
} catch (error) {
|
|
1404
1417
|
if (options?.signal?.aborted) throw options.signal.reason ?? error;
|
|
1405
|
-
return
|
|
1418
|
+
return [runFailed(name ?? "", toSandboxTaskError(error)), void 0];
|
|
1406
1419
|
}
|
|
1407
1420
|
}
|
|
1408
1421
|
//#endregion
|
|
@@ -1,18 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
//#region src/task/runtime/provider-loader.d.ts
|
|
4
|
-
export interface ResolvedTaskSandbox {
|
|
5
|
-
provider: SandboxTaskDriver;
|
|
6
|
-
resolveSandbox: (requirements: readonly string[]) => Promise<Sandbox>;
|
|
7
|
-
sandboxId?: string;
|
|
8
|
-
}
|
|
9
|
-
export interface SandboxTaskRuntimeProvider {
|
|
10
|
-
resolveTaskSandbox: (options: {
|
|
11
|
-
local: SandboxTaskDefinitionOptions;
|
|
12
|
-
provider: SandboxTaskDefinitionDriverOptions & {
|
|
13
|
-
driver: SandboxTaskDriver;
|
|
14
|
-
};
|
|
15
|
-
} | any) => Promise<ResolvedTaskSandbox>;
|
|
16
|
-
}
|
|
17
|
-
export declare function loadSandboxTaskRuntimeProvider(provider: SandboxTaskDriver): Promise<SandboxTaskRuntimeProvider>;
|
|
18
|
-
//#endregion
|
|
1
|
+
import { n as SandboxTaskRuntimeProvider, r as loadSandboxTaskRuntimeProvider, t as ResolvedTaskSandbox } from "../../provider-loader-BDgDJ6bX.js";
|
|
2
|
+
export { ResolvedTaskSandbox, SandboxTaskRuntimeProvider, loadSandboxTaskRuntimeProvider };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as sandboxTaskErrorDiagnostics } from "../../error-diagnostics-
|
|
1
|
+
import { t as sandboxTaskErrorDiagnostics } from "../../error-diagnostics-BNQwU9yq.js";
|
|
2
2
|
//#region src/task/runtime/provider-loader.ts
|
|
3
3
|
const dynamicImport = new Function("specifier", "return import(specifier)");
|
|
4
4
|
async function loadSandboxTaskRuntimeProvider(provider) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { l as Sandbox } from "../../../index-DsoQAUb7.js";
|
|
2
|
-
import { n as CloudflareSandboxTaskDefinitionDriverOptions, u as SandboxTaskDefinitionOptions } from "../../../module-types-
|
|
2
|
+
import { n as CloudflareSandboxTaskDefinitionDriverOptions, u as SandboxTaskDefinitionOptions } from "../../../module-types-BoOZiNN4.js";
|
|
3
3
|
//#region src/task/runtime/providers/cloudflare.d.ts
|
|
4
4
|
type SandboxTaskOptions = {
|
|
5
5
|
local: SandboxTaskDefinitionOptions;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { resolveCloudflareSandbox } from "../../../internal/cloudflare.js";
|
|
2
|
-
import { t as sandboxTaskErrorDiagnostics } from "../../../error-diagnostics-
|
|
2
|
+
import { t as sandboxTaskErrorDiagnostics } from "../../../error-diagnostics-BNQwU9yq.js";
|
|
3
3
|
import { t as getActiveCloudflareEnv } from "../../../cloudflare-env-lookup-DzI6Xv1Y.js";
|
|
4
4
|
//#region src/task/runtime/providers/cloudflare.ts
|
|
5
5
|
/** Resolve the Sandbox namespace from the bindings of the active Cloudflare request. */
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { t as ResolvedTaskSandbox } from "../../../provider-loader-BDgDJ6bX.js";
|
|
2
|
+
//#region src/task/runtime/providers/local.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* `vite dev` runs each Sandbox Task as a Node process on this machine, in a temporary directory that the run removes.
|
|
5
|
+
* The process is not isolated: the Sandbox `executionAuthority` says `isolation: "none"`.
|
|
6
|
+
*/
|
|
7
|
+
export declare function resolveLocalTaskSandbox(): ResolvedTaskSandbox;
|
|
8
|
+
//#endregion
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { a as resolveRemoteSandboxRuntime } from "../../../remote-70ZVZZlq.js";
|
|
2
|
+
import { t as createTrustedHostRuntime } from "../../../trusted-host-RanFsFSB.js";
|
|
3
|
+
//#region src/task/runtime/providers/local.ts
|
|
4
|
+
/**
|
|
5
|
+
* `vite dev` runs each Sandbox Task as a Node process on this machine, in a temporary directory that the run removes.
|
|
6
|
+
* The process is not isolated: the Sandbox `executionAuthority` says `isolation: "none"`.
|
|
7
|
+
*/
|
|
8
|
+
function resolveLocalTaskSandbox() {
|
|
9
|
+
return {
|
|
10
|
+
provider: "local",
|
|
11
|
+
resolveSandbox: async (requirements) => await resolveRemoteSandboxRuntime(createTrustedHostRuntime(), requirements)
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
//#endregion
|
|
15
|
+
export { resolveLocalTaskSandbox };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { l as Sandbox } from "../../../index-DsoQAUb7.js";
|
|
2
|
-
import {
|
|
2
|
+
import { _ as VercelSandboxTaskDriverOptions, u as SandboxTaskDefinitionOptions } from "../../../module-types-BoOZiNN4.js";
|
|
3
3
|
//#region src/task/runtime/providers/vercel.d.ts
|
|
4
4
|
type SandboxTaskOptions = {
|
|
5
5
|
local: SandboxTaskDefinitionOptions;
|