@ai-sdk/sandbox-vercel 1.0.124 → 1.0.126
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 +19 -0
- package/README.md +13 -68
- package/dist/index.d.ts +60 -32
- package/dist/index.js +381 -275
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/index.ts +10 -1
- package/src/utils.ts +313 -0
- package/src/vercel-legacy-sandbox-provider.ts +221 -0
- package/src/vercel-network-sandbox-session.ts +5 -5
- package/src/vercel-sandbox-session.ts +5 -5
- package/src/vercel-sandbox.ts +156 -430
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# @ai-sdk/sandbox-vercel
|
|
2
2
|
|
|
3
|
+
## 1.0.126
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 31742b9: feat(harness): refactor sandbox APIs for cleaner separation of concerns from harness layer, more intuitive DX regardless of how your sandbox is configured, and streamlined handling of sandbox templates/snapshots
|
|
8
|
+
- Updated dependencies [af9597b]
|
|
9
|
+
- Updated dependencies [31742b9]
|
|
10
|
+
- Updated dependencies [bc49f78]
|
|
11
|
+
- @ai-sdk/harness@1.0.126
|
|
12
|
+
- @ai-sdk/provider-utils@5.0.49
|
|
13
|
+
|
|
14
|
+
## 1.0.125
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- Updated dependencies [be877ff]
|
|
19
|
+
- @ai-sdk/provider-utils@5.0.48
|
|
20
|
+
- @ai-sdk/harness@1.0.125
|
|
21
|
+
|
|
3
22
|
## 1.0.124
|
|
4
23
|
|
|
5
24
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
_This package is **experimental**._
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Sandbox session implementation for [Vercel Sandbox](https://vercel.com/docs/vercel-sandbox).
|
|
6
6
|
|
|
7
7
|
## Setup
|
|
8
8
|
|
|
@@ -12,21 +12,13 @@ npm i @ai-sdk/sandbox-vercel
|
|
|
12
12
|
|
|
13
13
|
## Usage
|
|
14
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
|
-
When neither `runtime` nor `image` is provided, the adapter uses the legacy
|
|
18
|
-
`node24` runtime on both Vercel Sandbox v2 and v3. Pass `image` explicitly to
|
|
19
|
-
opt into a v3 managed image such as `vercel/sandbox/universal`.
|
|
20
|
-
|
|
21
15
|
```ts
|
|
22
|
-
import {
|
|
16
|
+
import { createVercelNetworkSandboxSession } from '@ai-sdk/sandbox-vercel';
|
|
23
17
|
|
|
24
|
-
const
|
|
18
|
+
const networkSandboxSession = await createVercelNetworkSandboxSession({
|
|
25
19
|
runtime: 'node24',
|
|
26
20
|
ports: [3000],
|
|
27
21
|
});
|
|
28
|
-
|
|
29
|
-
const networkSandboxSession = await vercelSandbox.createSession();
|
|
30
22
|
const sandboxSession = networkSandboxSession.restricted();
|
|
31
23
|
|
|
32
24
|
await sandboxSession.writeTextFile({ path: 'hello.txt', content: 'hi' });
|
|
@@ -35,67 +27,20 @@ const { stdout } = await sandboxSession.run({
|
|
|
35
27
|
command: 'cat hello.txt',
|
|
36
28
|
});
|
|
37
29
|
console.log(stdout); // "hi"
|
|
38
|
-
await networkSandboxSession.
|
|
30
|
+
await networkSandboxSession.destroy();
|
|
39
31
|
```
|
|
40
32
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
Vercel Sandbox accepts `VERCEL_OIDC_TOKEN`, or explicit `token`, `teamId`, and
|
|
44
|
-
`projectId` settings. For local OIDC authentication, link the application with
|
|
45
|
-
`vercel link`, run `vercel env pull`, and load the generated `.env.local` before
|
|
46
|
-
starting it.
|
|
47
|
-
|
|
48
|
-
Credential resolution failures throw
|
|
49
|
-
`HarnessSandboxAuthenticationError` from `@ai-sdk/harness` and preserve the
|
|
50
|
-
underlying Vercel SDK error as `cause`.
|
|
51
|
-
|
|
52
|
-
`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`, `getPortEndpoint`, `setNetworkPolicy`, `setRequestTransformations`, `addRequestTransformations`, `stop`) that only the harness should reach for. `getPortUrl` remains available as a deprecated compatibility wrapper.
|
|
33
|
+
### Use cases
|
|
53
34
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
runtime: 'node24',
|
|
59
|
-
ports: [3000],
|
|
60
|
-
timeout: 10 * 60 * 1000,
|
|
61
|
-
networkPolicy: {
|
|
62
|
-
allow: ['api.example.com'],
|
|
63
|
-
subnets: { deny: ['169.254.169.254/32'] },
|
|
64
|
-
},
|
|
65
|
-
});
|
|
66
|
-
```
|
|
35
|
+
- Create a network sandbox session with `createVercelNetworkSandboxSession()` and pass it to `HarnessAgent.createSession({ sandboxSession })`. For reusable snapshots, pass `template: await agent.getSandboxTemplate()` to the creator function.
|
|
36
|
+
- Set `sandboxId` to name a new sandbox, or persist the returned session's `id`. Creation never resumes an existing sandbox and a conflicting name fails; use `resumeVercelNetworkSandboxSession({ sandboxId })` to reattach.
|
|
37
|
+
- Take a network sandbox session's process-restricted subset with `networkSandboxSession.restricted()` and use it with AI SDK tools that accept `experimental_sandbox`.
|
|
38
|
+
- Adapt an existing native `Sandbox` with `createVercelSandboxSessionFromNativeSandbox(nativeSandbox)` and use it with AI SDK tools that accept `experimental_sandbox`.
|
|
67
39
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
```ts
|
|
71
|
-
import { createVercelSandbox } from '@ai-sdk/sandbox-vercel';
|
|
72
|
-
import { Sandbox } from '@vercel/sandbox';
|
|
73
|
-
|
|
74
|
-
const sandbox = createVercelSandbox({
|
|
75
|
-
sandbox: await Sandbox.create({ runtime: 'node24', ports: [3000] }),
|
|
76
|
-
});
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
### Mid-session network policy
|
|
80
|
-
|
|
81
|
-
Once the network sandbox session is alive, the host can update outbound network policy on the running sandbox:
|
|
82
|
-
|
|
83
|
-
```ts
|
|
84
|
-
await networkSandboxSession.setNetworkPolicy?.({
|
|
85
|
-
mode: 'custom',
|
|
86
|
-
allowedHosts: ['api.example.com'],
|
|
87
|
-
deniedCIDRs: ['169.254.169.254/32'],
|
|
88
|
-
});
|
|
89
|
-
```
|
|
40
|
+
## Authentication
|
|
90
41
|
|
|
91
|
-
`
|
|
42
|
+
Vercel Sandbox accepts `VERCEL_OIDC_TOKEN`, or explicit `token`, `teamId`, and `projectId` settings. For local OIDC authentication, link the application with `vercel link`, run `vercel env pull`, and load the generated `.env.local` before starting it.
|
|
92
43
|
|
|
93
|
-
|
|
44
|
+
## Request transformations and credential brokering
|
|
94
45
|
|
|
95
|
-
Vercel Sandbox supports outbound request transformations for use cases such as
|
|
96
|
-
credential brokering. `setRequestTransformations()` replaces the managed rules,
|
|
97
|
-
while `addRequestTransformations()` adds rules without replacing unrelated
|
|
98
|
-
rules. Re-adding a managed rule with the same request matcher and transformed
|
|
99
|
-
header names refreshes that rule in place, which keeps resumed credential
|
|
100
|
-
brokering idempotent. Network access policies remain authoritative over which
|
|
101
|
-
hosts can be reached.
|
|
46
|
+
Vercel Sandbox supports outbound request transformations for use cases such as credential brokering. `setRequestTransformations()` replaces the managed rules, while `addRequestTransformations()` adds rules without replacing unrelated rules.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,34 +1,15 @@
|
|
|
1
|
-
import { HarnessV1SandboxProvider, HarnessV1NetworkSandboxSession } from '@ai-sdk/harness';
|
|
1
|
+
import { HarnessV1SandboxProvider, HarnessV1NetworkSandboxSession, HarnessV1SandboxSessionCreateOptions, HarnessV1SandboxSessionResumeOptions } from '@ai-sdk/harness';
|
|
2
2
|
import { Experimental_SandboxSession } from '@ai-sdk/provider-utils';
|
|
3
3
|
import { Sandbox } from '@vercel/sandbox';
|
|
4
4
|
|
|
5
|
+
type VercelSandboxCreateParams$1 = NonNullable<Parameters<typeof Sandbox.create>[0]>;
|
|
6
|
+
type DistributiveOmit$1<T, K extends keyof any> = T extends unknown ? Omit<T, K> : never;
|
|
7
|
+
type VercelSandboxCreationSettings$1 = DistributiveOmit$1<VercelSandboxCreateParams$1, 'onResume'> & {
|
|
8
|
+
sandbox?: never;
|
|
9
|
+
name?: string;
|
|
10
|
+
};
|
|
5
11
|
/**
|
|
6
|
-
*
|
|
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:
|
|
12
|
+
* Settings for `createVercelSandbox`. Two mutually-exclusive shapes:
|
|
32
13
|
*
|
|
33
14
|
* - `{ sandbox }` — wrap an already-created `@vercel/sandbox` `Sandbox`. The
|
|
34
15
|
* caller owns its lifecycle; the provider's `stop()` and `destroy()` are
|
|
@@ -38,13 +19,13 @@ type VercelSandboxCreateParams = DistributiveOmit<NonNullable<Parameters<typeof
|
|
|
38
19
|
* `Sandbox.getOrCreate` to maintain a persistent named template snapshot
|
|
39
20
|
* keyed by the recipe identity, and forks an ephemeral sandbox per session
|
|
40
21
|
* from the snapshot. Use `name` to override the auto-derived template name.
|
|
22
|
+
*
|
|
23
|
+
* @deprecated Use `VercelNetworkSandboxSessionCreateOptions` for new sessions.
|
|
41
24
|
*/
|
|
42
25
|
type VercelSandboxSettings = {
|
|
43
26
|
sandbox: Sandbox;
|
|
44
|
-
} |
|
|
45
|
-
|
|
46
|
-
name?: string;
|
|
47
|
-
});
|
|
27
|
+
} | VercelSandboxCreationSettings$1;
|
|
28
|
+
/** @deprecated Use `createVercelNetworkSandboxSession` instead. */
|
|
48
29
|
declare function createVercelSandbox(settings?: VercelSandboxSettings): HarnessV1SandboxProvider;
|
|
49
30
|
/**
|
|
50
31
|
* `HarnessV1SandboxProvider` implementation backed by `@vercel/sandbox`.
|
|
@@ -52,6 +33,7 @@ declare function createVercelSandbox(settings?: VercelSandboxSettings): HarnessV
|
|
|
52
33
|
* to a `HarnessAgent` (or call `createSession()` directly if you want raw
|
|
53
34
|
* access to a network sandbox session).
|
|
54
35
|
*/
|
|
36
|
+
/** @deprecated Use `createVercelNetworkSandboxSession` instead. */
|
|
55
37
|
declare class VercelSandboxProvider implements HarnessV1SandboxProvider {
|
|
56
38
|
private readonly settings;
|
|
57
39
|
readonly specificationVersion: "harness-sandbox-v1";
|
|
@@ -71,4 +53,50 @@ declare class VercelSandboxProvider implements HarnessV1SandboxProvider {
|
|
|
71
53
|
}) => Promise<HarnessV1NetworkSandboxSession>;
|
|
72
54
|
}
|
|
73
55
|
|
|
74
|
-
|
|
56
|
+
/**
|
|
57
|
+
* Flattens an intersection of object types into a single object type so the
|
|
58
|
+
* resolved shape displays as its named properties rather than a chain of
|
|
59
|
+
* `A & B & C`.
|
|
60
|
+
*/
|
|
61
|
+
type Prettify<T> = {
|
|
62
|
+
[K in keyof T]: T[K];
|
|
63
|
+
} & {};
|
|
64
|
+
/**
|
|
65
|
+
* Distributes `Omit` across each member of a union instead of collapsing the
|
|
66
|
+
* union to its common keys. `Sandbox.create`'s parameter is a union (a
|
|
67
|
+
* git/tarball/no-source create variant and a snapshot-source create variant),
|
|
68
|
+
* so a plain `Omit` would discard keys absent from any one member (e.g.
|
|
69
|
+
* `runtime`, which the snapshot variant lacks) and merge the `source` shapes.
|
|
70
|
+
* Applying `Omit` per-member preserves every variant intact; the `Prettify`
|
|
71
|
+
* wrapper collapses each member's intersections into a readable object shape.
|
|
72
|
+
*/
|
|
73
|
+
type DistributiveOmit<T, K extends keyof any> = T extends unknown ? Prettify<Omit<T, K>> : never;
|
|
74
|
+
/**
|
|
75
|
+
* Parameters forwarded to `@vercel/sandbox`'s `Sandbox.create` when creating
|
|
76
|
+
* a sandbox from scratch. Aliased directly from the underlying SDK so the
|
|
77
|
+
* full surface — every option Vercel supports, including its native
|
|
78
|
+
* `NetworkPolicy` — is available without us re-declaring it.
|
|
79
|
+
*/
|
|
80
|
+
type VercelSandboxCreateParams = DistributiveOmit<NonNullable<Parameters<typeof Sandbox.create>[0]>, 'onResume'>;
|
|
81
|
+
|
|
82
|
+
type VercelNativeSandboxSession = Sandbox;
|
|
83
|
+
type VercelSandboxCreationSettings = VercelSandboxCreateParams & {
|
|
84
|
+
sandbox?: never;
|
|
85
|
+
name?: string;
|
|
86
|
+
};
|
|
87
|
+
type VercelCreationSettings = DistributiveOmit<VercelSandboxCreationSettings, 'sandbox'>;
|
|
88
|
+
type VercelNetworkSandboxSessionCreateOptions = Prettify<HarnessV1SandboxSessionCreateOptions<VercelCreationSettings> & {
|
|
89
|
+
sandbox?: never;
|
|
90
|
+
}>;
|
|
91
|
+
type VercelLookupSettings = DistributiveOmit<NonNullable<Parameters<typeof Sandbox.get>[0]>, 'name' | 'resume'> & {
|
|
92
|
+
name?: never;
|
|
93
|
+
resume?: never;
|
|
94
|
+
};
|
|
95
|
+
type VercelNetworkSandboxSessionResumeOptions = Prettify<HarnessV1SandboxSessionResumeOptions<VercelLookupSettings>>;
|
|
96
|
+
|
|
97
|
+
declare function createVercelNetworkSandboxSession(options?: VercelNetworkSandboxSessionCreateOptions): Promise<HarnessV1NetworkSandboxSession>;
|
|
98
|
+
declare function resumeVercelNetworkSandboxSession(options: VercelNetworkSandboxSessionResumeOptions): Promise<HarnessV1NetworkSandboxSession>;
|
|
99
|
+
declare function createVercelSandboxSessionFromNativeSandbox(nativeSandbox: VercelNativeSandboxSession): Experimental_SandboxSession;
|
|
100
|
+
declare function createVercelNetworkSandboxSessionFromNativeSandbox(nativeSandbox: VercelNativeSandboxSession): HarnessV1NetworkSandboxSession;
|
|
101
|
+
|
|
102
|
+
export { type VercelNativeSandboxSession, type VercelNetworkSandboxSessionCreateOptions, type VercelNetworkSandboxSessionResumeOptions, VercelSandboxProvider, type VercelSandboxSettings, createVercelNetworkSandboxSession, createVercelNetworkSandboxSessionFromNativeSandbox, createVercelSandbox, createVercelSandboxSessionFromNativeSandbox, resumeVercelNetworkSandboxSession };
|