@ai-sdk/sandbox-vercel 0.0.0 → 1.0.0-beta.14

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/CHANGELOG.md ADDED
@@ -0,0 +1,109 @@
1
+ # @ai-sdk/sandbox-vercel
2
+
3
+ ## 1.0.0-beta.14
4
+
5
+ ### Patch Changes
6
+
7
+ - b8396f0: trigger initial beta release
8
+ - Updated dependencies [b8396f0]
9
+ - @ai-sdk/harness@1.0.0-beta.14
10
+ - @ai-sdk/provider-utils@5.0.0-beta.49
11
+
12
+ ## 1.0.0-canary.13
13
+
14
+ ### Patch Changes
15
+
16
+ - @ai-sdk/harness@1.0.0-canary.13
17
+
18
+ ## 1.0.0-canary.12
19
+
20
+ ### Patch Changes
21
+
22
+ - @ai-sdk/harness@1.0.0-canary.12
23
+
24
+ ## 1.0.0-canary.11
25
+
26
+ ### Patch Changes
27
+
28
+ - Updated dependencies [be83911]
29
+ - @ai-sdk/harness@1.0.0-canary.11
30
+
31
+ ## 1.0.0-canary.10
32
+
33
+ ### Patch Changes
34
+
35
+ - @ai-sdk/harness@1.0.0-canary.10
36
+
37
+ ## 1.0.0-canary.9
38
+
39
+ ### Patch Changes
40
+
41
+ - @ai-sdk/harness@1.0.0-canary.9
42
+
43
+ ## 1.0.0-canary.8
44
+
45
+ ### Patch Changes
46
+
47
+ - Updated dependencies [aae0138]
48
+ - @ai-sdk/harness@1.0.0-canary.8
49
+
50
+ ## 1.0.0-canary.7
51
+
52
+ ### Patch Changes
53
+
54
+ - e551763: fix(harness): avoid using peer dependencies for underlying harness and sandbox SDKs
55
+ - Updated dependencies [3d87086]
56
+ - Updated dependencies [aeda373]
57
+ - Updated dependencies [1ea15a3]
58
+ - Updated dependencies [375fdd7]
59
+ - Updated dependencies [b4507d5]
60
+ - @ai-sdk/harness@1.0.0-canary.7
61
+ - @ai-sdk/provider-utils@5.0.0-canary.48
62
+
63
+ ## 1.0.0-canary.6
64
+
65
+ ### Patch Changes
66
+
67
+ - @ai-sdk/harness@1.0.0-canary.6
68
+
69
+ ## 1.0.0-canary.5
70
+
71
+ ### Patch Changes
72
+
73
+ - Updated dependencies [d77bed4]
74
+ - Updated dependencies [bae5e2b]
75
+ - @ai-sdk/harness@1.0.0-canary.5
76
+ - @ai-sdk/provider-utils@5.0.0-canary.47
77
+
78
+ ## 1.0.0-canary.4
79
+
80
+ ### Patch Changes
81
+
82
+ - Updated dependencies [3d9a50c]
83
+ - @ai-sdk/harness@1.0.0-canary.4
84
+
85
+ ## 1.0.0-canary.3
86
+
87
+ ### Patch Changes
88
+
89
+ - Updated dependencies [21d3d60]
90
+ - @ai-sdk/harness@1.0.0-canary.3
91
+
92
+ ## 1.0.0-canary.2
93
+
94
+ ### Patch Changes
95
+
96
+ - 6c7a3e5: Start the `1.0.0` canary release line for the experimental harness and sandbox packages. They were unintentionally published as `0.0.0-canary.*` because they were scaffolded with a `0.0.0-canary.0` premajor version, which semver could not advance past on a major bump.
97
+ - Updated dependencies [6c7a3e5]
98
+ - @ai-sdk/harness@1.0.0-canary.2
99
+
100
+ ## 0.0.0-canary.1
101
+
102
+ ### Major Changes
103
+
104
+ - 9d6dbe0: feat(harness): add sandbox specific expansion for harness abstraction, add `sandbox-just-bash` and `sandbox-vercel`
105
+
106
+ ### Patch Changes
107
+
108
+ - Updated dependencies [9d6dbe0]
109
+ - @ai-sdk/harness@0.0.0-canary.1
package/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright 2023 Vercel, Inc.
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,76 @@
1
+ # AI SDK - Vercel Sandbox
2
+
3
+ _This package is **experimental**._
4
+
5
+ `HarnessV1SandboxProvider` implementation for [Vercel Sandbox](https://vercel.com/docs/vercel-sandbox).
6
+
7
+ ## Setup
8
+
9
+ ```bash
10
+ npm i @ai-sdk/sandbox-vercel
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ The factory is synchronous. The returned provider is stable; the actual `@vercel/sandbox` `Sandbox` is created on demand inside `provider.createSession()`.
16
+
17
+ ```ts
18
+ import { createVercelSandbox } from '@ai-sdk/sandbox-vercel';
19
+
20
+ const vercelSandbox = createVercelSandbox({
21
+ runtime: 'node24',
22
+ ports: [3000],
23
+ });
24
+
25
+ const networkSandboxSession = await vercelSandbox.createSession();
26
+ const sandboxSession = networkSandboxSession.restricted();
27
+
28
+ await sandboxSession.writeTextFile({ path: 'hello.txt', content: 'hi' });
29
+
30
+ const { stdout } = await sandboxSession.run({
31
+ command: 'cat hello.txt',
32
+ });
33
+ console.log(stdout); // "hi"
34
+ await networkSandboxSession.stop();
35
+ ```
36
+
37
+ `networkSandboxSession.restricted()` is typed as `Experimental_SandboxSession`, so it's safe to pass to AI SDK tools that accept `experimental_sandbox`. The network sandbox session itself carries the infra surface (`ports`, `getPortUrl`, `setNetworkPolicy`, `stop`) that only the harness should reach for.
38
+
39
+ The flat-field settings are aliased directly from `@vercel/sandbox`'s `Sandbox.create` parameters, so every option Vercel supports — including its native `NetworkPolicy` — is available without re-declaration:
40
+
41
+ ```ts
42
+ const sandbox = createVercelSandbox({
43
+ runtime: 'node24',
44
+ ports: [3000],
45
+ timeout: 10 * 60 * 1000,
46
+ networkPolicy: {
47
+ allow: ['api.example.com'],
48
+ subnets: { deny: ['169.254.169.254/32'] },
49
+ },
50
+ });
51
+ ```
52
+
53
+ To wrap an already-created `@vercel/sandbox` `Sandbox` instead — e.g. when you need credentials or options outside the factory's settings, or you want to share one sandbox across multiple harness sessions — pass it via `sandbox`. Install `@vercel/sandbox` directly if your application imports `Sandbox`. The network sandbox session's `stop()` is a no-op in this case; the caller owns the lifecycle.
54
+
55
+ ```ts
56
+ import { createVercelSandbox } from '@ai-sdk/sandbox-vercel';
57
+ import { Sandbox } from '@vercel/sandbox';
58
+
59
+ const sandbox = createVercelSandbox({
60
+ sandbox: await Sandbox.create({ runtime: 'node24', ports: [3000] }),
61
+ });
62
+ ```
63
+
64
+ ### Mid-session network policy
65
+
66
+ Once the network sandbox session is alive, the host can update outbound network policy on the running sandbox:
67
+
68
+ ```ts
69
+ await networkSandboxSession.setNetworkPolicy?.({
70
+ mode: 'custom',
71
+ allowedHosts: ['api.example.com'],
72
+ deniedCIDRs: ['169.254.169.254/32'],
73
+ });
74
+ ```
75
+
76
+ `HarnessV1NetworkPolicy` is the harness-level abstraction used here. The provider translates it to `@vercel/sandbox`'s native `NetworkPolicy` for enforcement.
@@ -0,0 +1,77 @@
1
+ import { HarnessV1SandboxProvider, HarnessV1NetworkSandboxSession } from '@ai-sdk/harness';
2
+ import { Experimental_SandboxSession } from '@ai-sdk/provider-utils';
3
+ import { Sandbox } from '@vercel/sandbox';
4
+
5
+ /**
6
+ * Flattens an intersection of object types into a single object type so the
7
+ * resolved shape displays as its named properties rather than a chain of
8
+ * `A & B & C`.
9
+ */
10
+ type Prettify<T> = {
11
+ [K in keyof T]: T[K];
12
+ } & {};
13
+ /**
14
+ * Distributes `Omit` across each member of a union instead of collapsing the
15
+ * union to its common keys. `Sandbox.create`'s parameter is a union (a
16
+ * git/tarball/no-source create variant and a snapshot-source create variant),
17
+ * so a plain `Omit` would discard keys absent from any one member (e.g.
18
+ * `runtime`, which the snapshot variant lacks) and merge the `source` shapes.
19
+ * Applying `Omit` per-member preserves every variant intact; the `Prettify`
20
+ * wrapper collapses each member's intersections into a readable object shape.
21
+ */
22
+ type DistributiveOmit<T, K extends keyof any> = T extends unknown ? Prettify<Omit<T, K>> : never;
23
+ /**
24
+ * Parameters forwarded to `@vercel/sandbox`'s `Sandbox.create` when creating
25
+ * a sandbox from scratch. Aliased directly from the underlying SDK so the
26
+ * full surface — every option Vercel supports, including its native
27
+ * `NetworkPolicy` — is available without us re-declaring it.
28
+ */
29
+ type VercelSandboxCreateParams = DistributiveOmit<NonNullable<Parameters<typeof Sandbox.create>[0]>, 'onResume'>;
30
+ /**
31
+ * Settings for {@link createVercelSandbox}. Two mutually-exclusive shapes:
32
+ *
33
+ * - `{ sandbox }` — wrap an already-created `@vercel/sandbox` `Sandbox`. The
34
+ * caller owns its lifecycle; the provider's `stop()` and `destroy()` are
35
+ * no-ops. Optionally declare `bridgePorts` to give the harness a port pool to
36
+ * lease from for concurrent sessions on the same provided sandbox.
37
+ * - {@link VercelSandboxCreateParams} fields — provider creates the underlying
38
+ * sandbox. When the adapter declares a bootstrap recipe the provider uses
39
+ * `Sandbox.getOrCreate` to maintain a persistent named template snapshot
40
+ * keyed by the recipe identity, and forks an ephemeral sandbox per session
41
+ * from the snapshot. Use `name` to override the auto-derived template name.
42
+ */
43
+ type VercelSandboxSettings = {
44
+ sandbox: Sandbox;
45
+ bridgePorts?: ReadonlyArray<number>;
46
+ } | (VercelSandboxCreateParams & {
47
+ sandbox?: never;
48
+ name?: string;
49
+ });
50
+ declare function createVercelSandbox(settings?: VercelSandboxSettings): HarnessV1SandboxProvider;
51
+ /**
52
+ * `HarnessV1SandboxProvider` implementation backed by `@vercel/sandbox`.
53
+ * Construct one via {@link createVercelSandbox} at module scope and pass it
54
+ * to a `HarnessAgent` (or call `createSession()` directly if you want raw
55
+ * access to a network sandbox session).
56
+ */
57
+ declare class VercelSandboxProvider implements HarnessV1SandboxProvider {
58
+ private readonly settings;
59
+ readonly specificationVersion: "harness-sandbox-v1";
60
+ readonly providerId = "vercel-sandbox";
61
+ readonly bridgePorts?: ReadonlyArray<number>;
62
+ constructor(settings: VercelSandboxSettings);
63
+ createSession: (options?: {
64
+ sessionId?: string;
65
+ abortSignal?: AbortSignal;
66
+ identity?: string;
67
+ onFirstCreate?: (session: Experimental_SandboxSession, opts: {
68
+ abortSignal?: AbortSignal;
69
+ }) => Promise<void>;
70
+ }) => Promise<HarnessV1NetworkSandboxSession>;
71
+ resumeSession: (options: {
72
+ sessionId: string;
73
+ abortSignal?: AbortSignal;
74
+ }) => Promise<HarnessV1NetworkSandboxSession>;
75
+ }
76
+
77
+ export { VercelSandboxProvider, type VercelSandboxSettings, createVercelSandbox };