@alchemy.run/e2b 0.0.0-stage → 2.0.0-beta.86
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/LICENSE +201 -0
- package/README.md +60 -2
- package/lib/ApiKey.d.ts +53 -0
- package/lib/ApiKey.d.ts.map +1 -0
- package/lib/ApiKey.js +107 -0
- package/lib/ApiKey.js.map +1 -0
- package/lib/AuthProvider.d.ts +60 -0
- package/lib/AuthProvider.d.ts.map +1 -0
- package/lib/AuthProvider.js +293 -0
- package/lib/AuthProvider.js.map +1 -0
- package/lib/Bootstrap.d.ts +7 -0
- package/lib/Bootstrap.d.ts.map +1 -0
- package/lib/Bootstrap.js +25 -0
- package/lib/Bootstrap.js.map +1 -0
- package/lib/ConnectSandbox.d.ts +67 -0
- package/lib/ConnectSandbox.d.ts.map +1 -0
- package/lib/ConnectSandbox.js +3 -0
- package/lib/ConnectSandbox.js.map +1 -0
- package/lib/ConnectSandboxHttp.d.ts +22 -0
- package/lib/ConnectSandboxHttp.d.ts.map +1 -0
- package/lib/ConnectSandboxHttp.js +30 -0
- package/lib/ConnectSandboxHttp.js.map +1 -0
- package/lib/Contributions.d.ts +7 -0
- package/lib/Contributions.d.ts.map +1 -0
- package/lib/Contributions.js +6 -0
- package/lib/Contributions.js.map +1 -0
- package/lib/CreateSandbox.d.ts +139 -0
- package/lib/CreateSandbox.d.ts.map +1 -0
- package/lib/CreateSandbox.js +3 -0
- package/lib/CreateSandbox.js.map +1 -0
- package/lib/CreateSandboxHttp.d.ts +22 -0
- package/lib/CreateSandboxHttp.d.ts.map +1 -0
- package/lib/CreateSandboxHttp.js +99 -0
- package/lib/CreateSandboxHttp.js.map +1 -0
- package/lib/CreateSecret.d.ts +57 -0
- package/lib/CreateSecret.d.ts.map +1 -0
- package/lib/CreateSecret.js +3 -0
- package/lib/CreateSecret.js.map +1 -0
- package/lib/CreateSecretHttp.d.ts +20 -0
- package/lib/CreateSecretHttp.d.ts.map +1 -0
- package/lib/CreateSecretHttp.js +64 -0
- package/lib/CreateSecretHttp.js.map +1 -0
- package/lib/CreateSnapshot.d.ts +53 -0
- package/lib/CreateSnapshot.d.ts.map +1 -0
- package/lib/CreateSnapshot.js +3 -0
- package/lib/CreateSnapshot.js.map +1 -0
- package/lib/CreateSnapshotHttp.d.ts +20 -0
- package/lib/CreateSnapshotHttp.d.ts.map +1 -0
- package/lib/CreateSnapshotHttp.js +41 -0
- package/lib/CreateSnapshotHttp.js.map +1 -0
- package/lib/CreateTemplate.d.ts +96 -0
- package/lib/CreateTemplate.d.ts.map +1 -0
- package/lib/CreateTemplate.js +3 -0
- package/lib/CreateTemplate.js.map +1 -0
- package/lib/CreateTemplateHttp.d.ts +20 -0
- package/lib/CreateTemplateHttp.d.ts.map +1 -0
- package/lib/CreateTemplateHttp.js +99 -0
- package/lib/CreateTemplateHttp.js.map +1 -0
- package/lib/CreateVolume.d.ts +58 -0
- package/lib/CreateVolume.d.ts.map +1 -0
- package/lib/CreateVolume.js +3 -0
- package/lib/CreateVolume.js.map +1 -0
- package/lib/CreateVolumeHttp.d.ts +20 -0
- package/lib/CreateVolumeHttp.d.ts.map +1 -0
- package/lib/CreateVolumeHttp.js +51 -0
- package/lib/CreateVolumeHttp.js.map +1 -0
- package/lib/Credentials.d.ts +18 -0
- package/lib/Credentials.d.ts.map +1 -0
- package/lib/Credentials.js +55 -0
- package/lib/Credentials.js.map +1 -0
- package/lib/E2BBindings.d.ts +35 -0
- package/lib/E2BBindings.d.ts.map +1 -0
- package/lib/E2BBindings.js +127 -0
- package/lib/E2BBindings.js.map +1 -0
- package/lib/Errors.d.ts +61 -0
- package/lib/Errors.d.ts.map +1 -0
- package/lib/Errors.js +23 -0
- package/lib/Errors.js.map +1 -0
- package/lib/InferEnv.d.ts +26 -0
- package/lib/InferEnv.d.ts.map +1 -0
- package/lib/InferEnv.js +1 -0
- package/lib/InferEnv.js.map +1 -0
- package/lib/MountVolume.d.ts +86 -0
- package/lib/MountVolume.d.ts.map +1 -0
- package/lib/MountVolume.js +3 -0
- package/lib/MountVolume.js.map +1 -0
- package/lib/MountVolumeLive.d.ts +23 -0
- package/lib/MountVolumeLive.d.ts.map +1 -0
- package/lib/MountVolumeLive.js +41 -0
- package/lib/MountVolumeLive.js.map +1 -0
- package/lib/Providers.d.ts +14 -0
- package/lib/Providers.d.ts.map +1 -0
- package/lib/Providers.js +23 -0
- package/lib/Providers.js.map +1 -0
- package/lib/ReadTeam.d.ts +41 -0
- package/lib/ReadTeam.d.ts.map +1 -0
- package/lib/ReadTeam.js +3 -0
- package/lib/ReadTeam.js.map +1 -0
- package/lib/ReadTeamHttp.d.ts +20 -0
- package/lib/ReadTeamHttp.d.ts.map +1 -0
- package/lib/ReadTeamHttp.js +40 -0
- package/lib/ReadTeamHttp.js.map +1 -0
- package/lib/ReadVolume.d.ts +25 -0
- package/lib/ReadVolume.d.ts.map +1 -0
- package/lib/ReadVolume.js +3 -0
- package/lib/ReadVolume.js.map +1 -0
- package/lib/ReadVolumeHttp.d.ts +20 -0
- package/lib/ReadVolumeHttp.d.ts.map +1 -0
- package/lib/ReadVolumeHttp.js +27 -0
- package/lib/ReadVolumeHttp.js.map +1 -0
- package/lib/ReadWebhook.d.ts +32 -0
- package/lib/ReadWebhook.d.ts.map +1 -0
- package/lib/ReadWebhook.js +3 -0
- package/lib/ReadWebhook.js.map +1 -0
- package/lib/ReadWebhookHttp.d.ts +20 -0
- package/lib/ReadWebhookHttp.d.ts.map +1 -0
- package/lib/ReadWebhookHttp.js +31 -0
- package/lib/ReadWebhookHttp.js.map +1 -0
- package/lib/ReadWriteVolume.d.ts +26 -0
- package/lib/ReadWriteVolume.d.ts.map +1 -0
- package/lib/ReadWriteVolume.js +3 -0
- package/lib/ReadWriteVolume.js.map +1 -0
- package/lib/ReadWriteVolumeHttp.d.ts +20 -0
- package/lib/ReadWriteVolumeHttp.d.ts.map +1 -0
- package/lib/ReadWriteVolumeHttp.js +27 -0
- package/lib/ReadWriteVolumeHttp.js.map +1 -0
- package/lib/Sandbox.d.ts +295 -0
- package/lib/Sandbox.d.ts.map +1 -0
- package/lib/Sandbox.js +351 -0
- package/lib/Sandbox.js.map +1 -0
- package/lib/SandboxClient.d.ts +226 -0
- package/lib/SandboxClient.d.ts.map +1 -0
- package/lib/SandboxClient.js +1 -0
- package/lib/SandboxClient.js.map +1 -0
- package/lib/SandboxEvents.d.ts +87 -0
- package/lib/SandboxEvents.d.ts.map +1 -0
- package/lib/SandboxEvents.js +39 -0
- package/lib/SandboxEvents.js.map +1 -0
- package/lib/SandboxEventsLive.d.ts +13 -0
- package/lib/SandboxEventsLive.d.ts.map +1 -0
- package/lib/SandboxEventsLive.js +80 -0
- package/lib/SandboxEventsLive.js.map +1 -0
- package/lib/Secret.d.ts +105 -0
- package/lib/Secret.d.ts.map +1 -0
- package/lib/Secret.js +161 -0
- package/lib/Secret.js.map +1 -0
- package/lib/Snapshot.d.ts +118 -0
- package/lib/Snapshot.d.ts.map +1 -0
- package/lib/Snapshot.js +158 -0
- package/lib/Snapshot.js.map +1 -0
- package/lib/Template.d.ts +313 -0
- package/lib/Template.d.ts.map +1 -0
- package/lib/Template.js +421 -0
- package/lib/Template.js.map +1 -0
- package/lib/Volume.d.ts +88 -0
- package/lib/Volume.d.ts.map +1 -0
- package/lib/Volume.js +136 -0
- package/lib/Volume.js.map +1 -0
- package/lib/VolumeFiles.d.ts +39 -0
- package/lib/VolumeFiles.d.ts.map +1 -0
- package/lib/VolumeFiles.js +1 -0
- package/lib/VolumeFiles.js.map +1 -0
- package/lib/Webhook.d.ts +83 -0
- package/lib/Webhook.d.ts.map +1 -0
- package/lib/Webhook.js +138 -0
- package/lib/Webhook.js.map +1 -0
- package/lib/WriteSecret.d.ts +34 -0
- package/lib/WriteSecret.d.ts.map +1 -0
- package/lib/WriteSecret.js +3 -0
- package/lib/WriteSecret.js.map +1 -0
- package/lib/WriteSecretHttp.d.ts +20 -0
- package/lib/WriteSecretHttp.d.ts.map +1 -0
- package/lib/WriteSecretHttp.js +37 -0
- package/lib/WriteSecretHttp.js.map +1 -0
- package/lib/WriteVolume.d.ts +25 -0
- package/lib/WriteVolume.d.ts.map +1 -0
- package/lib/WriteVolume.js +3 -0
- package/lib/WriteVolume.js.map +1 -0
- package/lib/WriteVolumeHttp.d.ts +20 -0
- package/lib/WriteVolumeHttp.d.ts.map +1 -0
- package/lib/WriteVolumeHttp.js +27 -0
- package/lib/WriteVolumeHttp.js.map +1 -0
- package/lib/index.d.ts +43 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +43 -0
- package/lib/index.js.map +1 -0
- package/lib/internal/Declared.d.ts +29 -0
- package/lib/internal/Declared.d.ts.map +1 -0
- package/lib/internal/Declared.js +31 -0
- package/lib/internal/Declared.js.map +1 -0
- package/lib/internal/Login.d.ts +45 -0
- package/lib/internal/Login.d.ts.map +1 -0
- package/lib/internal/Login.js +157 -0
- package/lib/internal/Login.js.map +1 -0
- package/lib/internal/Ownership.d.ts +29 -0
- package/lib/internal/Ownership.d.ts.map +1 -0
- package/lib/internal/Ownership.js +49 -0
- package/lib/internal/Ownership.js.map +1 -0
- package/lib/internal/Program.d.ts +31 -0
- package/lib/internal/Program.d.ts.map +1 -0
- package/lib/internal/Program.js +60 -0
- package/lib/internal/Program.js.map +1 -0
- package/lib/internal/SandboxHandle.d.ts +25 -0
- package/lib/internal/SandboxHandle.d.ts.map +1 -0
- package/lib/internal/SandboxHandle.js +316 -0
- package/lib/internal/SandboxHandle.js.map +1 -0
- package/lib/internal/SnapshotBuild.d.ts +19 -0
- package/lib/internal/SnapshotBuild.d.ts.map +1 -0
- package/lib/internal/SnapshotBuild.js +49 -0
- package/lib/internal/SnapshotBuild.js.map +1 -0
- package/lib/internal/Tar.d.ts +10 -0
- package/lib/internal/Tar.d.ts.map +1 -0
- package/lib/internal/Tar.js +61 -0
- package/lib/internal/Tar.js.map +1 -0
- package/lib/internal/TemplateBuild.d.ts +142 -0
- package/lib/internal/TemplateBuild.d.ts.map +1 -0
- package/lib/internal/TemplateBuild.js +220 -0
- package/lib/internal/TemplateBuild.js.map +1 -0
- package/lib/internal/TemplatePlan.d.ts +57 -0
- package/lib/internal/TemplatePlan.d.ts.map +1 -0
- package/lib/internal/TemplatePlan.js +185 -0
- package/lib/internal/TemplatePlan.js.map +1 -0
- package/lib/internal/VolumeHttp.d.ts +5 -0
- package/lib/internal/VolumeHttp.d.ts.map +1 -0
- package/lib/internal/VolumeHttp.js +46 -0
- package/lib/internal/VolumeHttp.js.map +1 -0
- package/package.json +78 -3
- package/src/ApiKey.ts +148 -0
- package/src/AuthProvider.ts +437 -0
- package/src/Bootstrap.ts +51 -0
- package/src/ConnectSandbox.ts +71 -0
- package/src/ConnectSandboxHttp.ts +38 -0
- package/src/Contributions.ts +9 -0
- package/src/CreateSandbox.ts +157 -0
- package/src/CreateSandboxHttp.ts +131 -0
- package/src/CreateSecret.ts +65 -0
- package/src/CreateSecretHttp.ts +94 -0
- package/src/CreateSnapshot.ts +64 -0
- package/src/CreateSnapshotHttp.ts +55 -0
- package/src/CreateTemplate.ts +135 -0
- package/src/CreateTemplateHttp.ts +152 -0
- package/src/CreateVolume.ts +65 -0
- package/src/CreateVolumeHttp.ts +80 -0
- package/src/Credentials.ts +81 -0
- package/src/E2BBindings.ts +160 -0
- package/src/Errors.ts +47 -0
- package/src/InferEnv.ts +27 -0
- package/src/MountVolume.ts +92 -0
- package/src/MountVolumeLive.ts +49 -0
- package/src/Providers.ts +48 -0
- package/src/ReadTeam.ts +55 -0
- package/src/ReadTeamHttp.ts +44 -0
- package/src/ReadVolume.ts +29 -0
- package/src/ReadVolumeHttp.ts +32 -0
- package/src/ReadWebhook.ts +41 -0
- package/src/ReadWebhookHttp.ts +42 -0
- package/src/ReadWriteVolume.ts +30 -0
- package/src/ReadWriteVolumeHttp.ts +32 -0
- package/src/Sandbox.ts +581 -0
- package/src/SandboxClient.ts +268 -0
- package/src/SandboxEvents.ts +101 -0
- package/src/SandboxEventsLive.ts +118 -0
- package/src/Secret.ts +229 -0
- package/src/Snapshot.ts +234 -0
- package/src/Template.ts +636 -0
- package/src/Volume.ts +173 -0
- package/src/VolumeFiles.ts +53 -0
- package/src/Webhook.ts +215 -0
- package/src/WriteSecret.ts +39 -0
- package/src/WriteSecretHttp.ts +43 -0
- package/src/WriteVolume.ts +29 -0
- package/src/WriteVolumeHttp.ts +32 -0
- package/src/globals.d.ts +2 -0
- package/src/index.ts +42 -0
- package/src/internal/Declared.ts +80 -0
- package/src/internal/Login.ts +210 -0
- package/src/internal/Ownership.ts +67 -0
- package/src/internal/Program.ts +75 -0
- package/src/internal/SandboxHandle.ts +534 -0
- package/src/internal/SnapshotBuild.ts +74 -0
- package/src/internal/Tar.ts +74 -0
- package/src/internal/TemplateBuild.ts +383 -0
- package/src/internal/TemplatePlan.ts +230 -0
- package/src/internal/VolumeHttp.ts +88 -0
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import type * as sandboxes from "@distilled.cloud/e2b/sandboxes";
|
|
2
|
+
import * as Binding from "alchemy/Binding";
|
|
3
|
+
import type { RuntimeContext } from "alchemy/RuntimeContext";
|
|
4
|
+
import type * as Effect from "effect/Effect";
|
|
5
|
+
import type { BoundVolumeMount, VolumeMount } from "./MountVolume.ts";
|
|
6
|
+
import type { E2BError, E2BSandbox } from "./SandboxClient.ts";
|
|
7
|
+
import type { Snapshot } from "./Snapshot.ts";
|
|
8
|
+
import type { Template } from "./Template.ts";
|
|
9
|
+
/** A template or snapshot sandboxes are created from. */
|
|
10
|
+
export type SandboxBase = Template | Snapshot;
|
|
11
|
+
/**
|
|
12
|
+
* E2B's `createSandbox` parameters. `templateID` defaults to the bound base;
|
|
13
|
+
* `metadata` is merged with the host's ownership stamp; `mounts` replaces
|
|
14
|
+
* E2B's `volumeMounts`.
|
|
15
|
+
*/
|
|
16
|
+
export type CreateSandboxOptions = Omit<sandboxes.CreateSandboxRequest, "templateID" | "volumeMounts"> & {
|
|
17
|
+
readonly templateID?: string;
|
|
18
|
+
/**
|
|
19
|
+
* Volumes to mount: a volume `CreateVolume` returned with a `path`, or a
|
|
20
|
+
* reference from `E2B.MountVolume`. A bound template's own mounts are
|
|
21
|
+
* added.
|
|
22
|
+
*/
|
|
23
|
+
readonly mounts?: ReadonlyArray<VolumeMount | BoundVolumeMount>;
|
|
24
|
+
};
|
|
25
|
+
/** E2B's `listSandboxes` filters, with `metadata` as a record instead of a query string. */
|
|
26
|
+
export type ListSandboxesOptions = Omit<sandboxes.ListSandboxesRequest, "metadata" | "nextToken"> & {
|
|
27
|
+
readonly metadata?: Readonly<Record<string, string>>;
|
|
28
|
+
};
|
|
29
|
+
/** E2B sandboxes: create, look up, list and kill them. */
|
|
30
|
+
export interface SandboxesClient {
|
|
31
|
+
/** Creates a sandbox from the bound base (or `templateID`). */
|
|
32
|
+
create(options?: CreateSandboxOptions): Effect.Effect<E2BSandbox, E2BError, RuntimeContext>;
|
|
33
|
+
/**
|
|
34
|
+
* A handle to an existing sandbox. A paused sandbox is resumed; `timeout`
|
|
35
|
+
* (seconds) resets its lifetime.
|
|
36
|
+
*/
|
|
37
|
+
connect(sandboxId: string, options?: {
|
|
38
|
+
readonly timeout?: number;
|
|
39
|
+
readonly memory?: boolean;
|
|
40
|
+
}): Effect.Effect<E2BSandbox, E2BError, RuntimeContext>;
|
|
41
|
+
/** A sandbox's details, without resuming it. */
|
|
42
|
+
get(sandboxId: string): Effect.Effect<sandboxes.SandboxDetail, E2BError, RuntimeContext>;
|
|
43
|
+
/** Sandboxes, filtered by metadata, state or template (the bound base by default). */
|
|
44
|
+
list(options?: ListSandboxesOptions): Effect.Effect<ReadonlyArray<sandboxes.ListedSandbox>, E2BError, RuntimeContext>;
|
|
45
|
+
/** Kills a sandbox. Killing one that is gone succeeds. */
|
|
46
|
+
kill(sandboxId: string): Effect.Effect<void, E2BError, RuntimeContext>;
|
|
47
|
+
/** The latest CPU, memory and disk metrics of several sandboxes at once, by id. */
|
|
48
|
+
metrics(sandboxIds: ReadonlyArray<string>): Effect.Effect<sandboxes.SandboxesWithMetrics, E2BError, RuntimeContext>;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Create and manage E2B sandboxes from a Worker, Function or any other host.
|
|
52
|
+
*
|
|
53
|
+
* `E2B.CreateSandbox(base)` creates sandboxes from a template or snapshot
|
|
54
|
+
* declared in the stack; `E2B.CreateSandbox()` takes the template per call.
|
|
55
|
+
* Both return the same client, whose calls take E2B's own parameters.
|
|
56
|
+
*
|
|
57
|
+
* Sandboxes created at run time are tagged with the stack, stage and
|
|
58
|
+
* binding (`alchemy::stack`, `alchemy::stage`, `alchemy::id` in their E2B
|
|
59
|
+
* metadata) and are not deleted when the stack is destroyed. List them by
|
|
60
|
+
* those tags to clean them up:
|
|
61
|
+
* `sandboxes.list({ metadata: { "alchemy::stack": "my-app", "alchemy::stage": "prod" } })`.
|
|
62
|
+
* Metadata you pass to `create` merges underneath; it never replaces the
|
|
63
|
+
* `alchemy::*` keys.
|
|
64
|
+
*
|
|
65
|
+
* The host gets its own E2B API key, minted at deploy and revoked when the
|
|
66
|
+
* host is destroyed. E2B keys are not scoped, so the key reaches the whole
|
|
67
|
+
* team; it is never the deployer's own.
|
|
68
|
+
*
|
|
69
|
+
* ### Creating sandboxes
|
|
70
|
+
* **Example:** One sandbox per request, killed when the request ends
|
|
71
|
+
* ```typescript
|
|
72
|
+
* const sandboxes = yield* E2B.CreateSandbox(Agent);
|
|
73
|
+
* // in fetch:
|
|
74
|
+
* const sandbox = yield* Effect.acquireRelease(
|
|
75
|
+
* sandboxes.create({ timeout: 120 }),
|
|
76
|
+
* (sandbox) => Effect.ignore(sandbox.kill()),
|
|
77
|
+
* );
|
|
78
|
+
* const result = yield* sandbox.exec("node --version");
|
|
79
|
+
* ```
|
|
80
|
+
*
|
|
81
|
+
* **Example:** A long-lived sandbox per task, found by metadata
|
|
82
|
+
* ```typescript
|
|
83
|
+
* const [existing] = yield* sandboxes.list({ metadata: { task }, state: ["running", "paused"] });
|
|
84
|
+
* const sandbox = existing
|
|
85
|
+
* ? yield* sandboxes.connect(existing.sandboxID)
|
|
86
|
+
* : yield* sandboxes.create({ metadata: { task }, autoPause: true, timeout: 1800 });
|
|
87
|
+
* ```
|
|
88
|
+
*
|
|
89
|
+
* ### Running commands
|
|
90
|
+
* `exec` runs to completion and returns `{ exitCode, stdout, stderr }`; a
|
|
91
|
+
* non-zero exit is returned, not failed. A string runs in a login shell, an
|
|
92
|
+
* array runs directly.
|
|
93
|
+
*
|
|
94
|
+
* **Example:** A shell line, an argument vector, stdin and a timeout
|
|
95
|
+
* ```typescript
|
|
96
|
+
* const test = yield* sandbox.exec("npm test", { cwd: "/home/user/app" });
|
|
97
|
+
* const version = yield* sandbox.exec(["node", "--version"]);
|
|
98
|
+
* const sorted = yield* sandbox.exec("sort", { stdin: "b\na\n" });
|
|
99
|
+
* const slow = yield* sandbox.exec("make", { timeout: "2 minutes" }); // E2B.ExecTimedOut
|
|
100
|
+
* ```
|
|
101
|
+
*
|
|
102
|
+
* **Example:** Stream a process, then wait for it
|
|
103
|
+
* ```typescript
|
|
104
|
+
* const build = yield* sandbox.start("npm run build", { cwd: "/home/user/app" });
|
|
105
|
+
* yield* build.output.pipe(
|
|
106
|
+
* Stream.runForEach((chunk) => Effect.log(new TextDecoder().decode(chunk.data))),
|
|
107
|
+
* );
|
|
108
|
+
* const { exitCode } = yield* build.wait;
|
|
109
|
+
* ```
|
|
110
|
+
*
|
|
111
|
+
* Closing the scope detaches: the process keeps running, and
|
|
112
|
+
* `sandbox.processes.attach({ pid })` picks it up again.
|
|
113
|
+
*
|
|
114
|
+
* **Example:** A terminal
|
|
115
|
+
* ```typescript
|
|
116
|
+
* const pty = yield* sandbox.pty.open({ cols: 120, rows: 40 });
|
|
117
|
+
* yield* pty.write("ls\n");
|
|
118
|
+
* yield* pty.resize({ cols: 160, rows: 48 });
|
|
119
|
+
* ```
|
|
120
|
+
*
|
|
121
|
+
* ### Network and secrets
|
|
122
|
+
* **Example:** Allow only GitHub and inject a token at egress
|
|
123
|
+
* ```typescript
|
|
124
|
+
* const github = yield* GitHubToken;
|
|
125
|
+
* const sandbox = yield* sandboxes.create({
|
|
126
|
+
* network: {
|
|
127
|
+
* allowOut: ["github.com", "*.github.com"],
|
|
128
|
+
* rules: { "api.github.com": [{ transform: { headers: { Authorization: `Bearer ${github.ref}` } } }] },
|
|
129
|
+
* },
|
|
130
|
+
* });
|
|
131
|
+
* ```
|
|
132
|
+
*
|
|
133
|
+
* @binding
|
|
134
|
+
* @product Sandbox
|
|
135
|
+
*/
|
|
136
|
+
export interface CreateSandbox extends Binding.Service<CreateSandbox, "E2B.CreateSandbox", (base?: SandboxBase) => Effect.Effect<SandboxesClient>> {
|
|
137
|
+
}
|
|
138
|
+
export declare const CreateSandbox: CreateSandbox;
|
|
139
|
+
//# sourceMappingURL=CreateSandbox.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CreateSandbox.d.ts","sources":["../src/CreateSandbox.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,SAAS,MAAM,gCAAgC,CAAC;AACjE,OAAO,KAAK,OAAO,MAAM,iBAAiB,CAAC;AAC3C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,KAAK,KAAK,MAAM,MAAM,eAAe,CAAC;AAC7C,OAAO,KAAK,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACtE,OAAO,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE9C,yDAAyD;AACzD,MAAM,MAAM,WAAW,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAE9C;;;;GAIG;AACH,MAAM,MAAM,oBAAoB,GAAG,IAAI,CACrC,SAAS,CA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AAM,CAAC,IAAI,EAAE,QAAQ,EAAE,cAAc,CAAC,CAAC;IACvE,mFAAmF;IACnF,OAAO,CACL,UAAU,EAAE,aAAa,CAAC,MAAM,CAAC,GAChC,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,oBAAoB,EAAE,QAAQ,EAAE,cAAc,CAAC,CAAC;CAC5E;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqFG;AACH,MAAM,WAAW,aAAc,SAAQ,OAAO,CAAC,OAAO,CACpD,aAAa,EACb,mBAAmB,EACnB,CAAC,IAAI,CAAC,EAAE,WAAW,KAAK,MAAM,CAAC,MAAM,CAAC,eAAe,CAAC,CACvD;CAAG;AAEJ,eAAO,MAAM,aAAa,eAAsD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CreateSandbox.js","sources":["../src/CreateSandbox.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,OAAO,MAAM,iBAAiB,CAAC;AA2J3C,MAAM,CAAC,MAAM,aAAa,GAAG,OAAO,CAAC,OAAO,CAAgB,mBAAmB,CAAC,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import * as Layer from "effect/Layer";
|
|
2
|
+
import { CreateSandbox } from "./CreateSandbox.ts";
|
|
3
|
+
/**
|
|
4
|
+
* HTTP implementation of {@link CreateSandbox}: E2B's control plane with the
|
|
5
|
+
* team key, and envd inside each sandbox with that sandbox's own token.
|
|
6
|
+
* Works on any host.
|
|
7
|
+
*
|
|
8
|
+
* ### Provide the layer
|
|
9
|
+
* **Example:** On a Cloudflare Worker
|
|
10
|
+
* ```typescript
|
|
11
|
+
* Effect.gen(function* () {
|
|
12
|
+
* const sandboxes = yield* E2B.CreateSandbox(Agent);
|
|
13
|
+
* // ...
|
|
14
|
+
* }).pipe(Effect.provide(E2B.CreateSandboxHttp))
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @layer
|
|
18
|
+
* @product Sandbox
|
|
19
|
+
* @provides E2B.CreateSandbox
|
|
20
|
+
*/
|
|
21
|
+
export declare const CreateSandboxHttp: Layer.Layer<CreateSandbox, never, never>;
|
|
22
|
+
//# sourceMappingURL=CreateSandboxHttp.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CreateSandboxHttp.d.ts","sources":["../src/CreateSandboxHttp.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AAEtC,OAAO,EAAE,aAAa,EAA0C,MAAM,oBAAoB,CAAC;AAO3F;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,iBAAiB,0CAoG7B,CAAC"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import * as sandboxes from "@distilled.cloud/e2b/sandboxes";
|
|
2
|
+
import * as Effect from "effect/Effect";
|
|
3
|
+
import * as Layer from "effect/Layer";
|
|
4
|
+
import * as Stream from "effect/Stream";
|
|
5
|
+
import { CreateSandbox } from "./CreateSandbox.js";
|
|
6
|
+
import { bindE2B, bindOwnerTags, metadataQuery } from "./E2BBindings.js";
|
|
7
|
+
import { SandboxBaseMissing } from "./Errors.js";
|
|
8
|
+
import { denyUnlisted, makeSandboxHandle } from "./internal/SandboxHandle.js";
|
|
9
|
+
/**
|
|
10
|
+
* HTTP implementation of {@link CreateSandbox}: E2B's control plane with the
|
|
11
|
+
* team key, and envd inside each sandbox with that sandbox's own token.
|
|
12
|
+
* Works on any host.
|
|
13
|
+
*
|
|
14
|
+
* ### Provide the layer
|
|
15
|
+
* **Example:** On a Cloudflare Worker
|
|
16
|
+
* ```typescript
|
|
17
|
+
* Effect.gen(function* () {
|
|
18
|
+
* const sandboxes = yield* E2B.CreateSandbox(Agent);
|
|
19
|
+
* // ...
|
|
20
|
+
* }).pipe(Effect.provide(E2B.CreateSandboxHttp))
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* @layer
|
|
24
|
+
* @product Sandbox
|
|
25
|
+
* @provides E2B.CreateSandbox
|
|
26
|
+
*/
|
|
27
|
+
export const CreateSandboxHttp = Layer.effect(CreateSandbox, Effect.gen(function* () {
|
|
28
|
+
return Effect.fn("E2B.CreateSandbox")(function* (base) {
|
|
29
|
+
const auth = yield* bindE2B;
|
|
30
|
+
const owner = yield* bindOwnerTags;
|
|
31
|
+
// Both a Template and a Snapshot expose the template id sandboxes boot from.
|
|
32
|
+
const baseId = base === undefined
|
|
33
|
+
? undefined
|
|
34
|
+
: yield* base.templateId.asEffect();
|
|
35
|
+
// A template program's own mounts (`E2B.MountVolume`) go on every sandbox.
|
|
36
|
+
const baseMounts = base !== undefined && base.Type === "E2B.Template"
|
|
37
|
+
? yield* base.mounts.asEffect()
|
|
38
|
+
: Effect.succeed([]);
|
|
39
|
+
/** The template's mounts and the call's own, by path (the call's win). */
|
|
40
|
+
const mountsOf = Effect.fn(function* (mounts) {
|
|
41
|
+
const byPath = new Map();
|
|
42
|
+
for (const mount of yield* baseMounts) {
|
|
43
|
+
byPath.set(mount.path, { name: mount.volume.name, path: mount.path });
|
|
44
|
+
}
|
|
45
|
+
for (const mount of mounts ?? []) {
|
|
46
|
+
const name = typeof mount.volume.name === "string" ? mount.volume.name : yield* mount.volume.name;
|
|
47
|
+
byPath.set(mount.path, { name, path: mount.path });
|
|
48
|
+
}
|
|
49
|
+
return [...byPath.values()];
|
|
50
|
+
});
|
|
51
|
+
const withStamp = Effect.fn(function* (metadata) {
|
|
52
|
+
return { ...metadata, ...(yield* owner) };
|
|
53
|
+
});
|
|
54
|
+
const client = {
|
|
55
|
+
create: Effect.fn("E2B.CreateSandbox.create")(function* (createOptions) {
|
|
56
|
+
const templateID = createOptions?.templateID ?? (baseId === undefined ? undefined : yield* baseId);
|
|
57
|
+
if (templateID === undefined) {
|
|
58
|
+
return yield* new SandboxBaseMissing({
|
|
59
|
+
message: "E2B.CreateSandbox() has no bound base: pass `templateID` to create()",
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
const domain = yield* auth.domain;
|
|
63
|
+
const { mounts, ...request } = createOptions ?? {};
|
|
64
|
+
const volumeMounts = yield* mountsOf(mounts);
|
|
65
|
+
const created = yield* auth.authorize(sandboxes.createSandbox({
|
|
66
|
+
...request,
|
|
67
|
+
...(volumeMounts.length === 0 ? {} : { volumeMounts }),
|
|
68
|
+
...(createOptions?.network === undefined
|
|
69
|
+
? {}
|
|
70
|
+
: { network: denyUnlisted(createOptions.network) }),
|
|
71
|
+
templateID,
|
|
72
|
+
metadata: yield* withStamp(createOptions?.metadata),
|
|
73
|
+
}));
|
|
74
|
+
return makeSandboxHandle(auth, created, domain);
|
|
75
|
+
}),
|
|
76
|
+
connect: Effect.fn("E2B.CreateSandbox.connect")(function* (sandboxId, connectOptions) {
|
|
77
|
+
const domain = yield* auth.domain;
|
|
78
|
+
const connected = yield* auth.authorize(sandboxes.connectSandbox({ sandboxID: sandboxId, ...connectOptions }));
|
|
79
|
+
return makeSandboxHandle(auth, connected, domain);
|
|
80
|
+
}),
|
|
81
|
+
get: (sandboxId) => auth.authorize(sandboxes.getSandbox({ sandboxID: sandboxId })),
|
|
82
|
+
list: Effect.fn("E2B.CreateSandbox.list")(function* (listOptions) {
|
|
83
|
+
const template = listOptions?.template ?? (baseId === undefined ? undefined : yield* baseId);
|
|
84
|
+
const all = yield* auth.authorize(Stream.runCollect(sandboxes.listSandboxes.items({
|
|
85
|
+
...listOptions,
|
|
86
|
+
...(template === undefined ? {} : { template }),
|
|
87
|
+
metadata: listOptions?.metadata === undefined
|
|
88
|
+
? undefined
|
|
89
|
+
: metadataQuery(listOptions.metadata),
|
|
90
|
+
})));
|
|
91
|
+
return Array.from(all);
|
|
92
|
+
}),
|
|
93
|
+
kill: (sandboxId) => auth.authorize(sandboxes.deleteSandbox({ sandboxID: sandboxId })).pipe(Effect.asVoid, Effect.catchTag("NotFound", () => Effect.void)),
|
|
94
|
+
metrics: (sandboxIds) => auth.authorize(sandboxes.listSandboxesMetrics({ sandbox_ids: [...sandboxIds] })),
|
|
95
|
+
};
|
|
96
|
+
return client;
|
|
97
|
+
});
|
|
98
|
+
}));
|
|
99
|
+
//# sourceMappingURL=CreateSandboxHttp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CreateSandboxHttp.js","sources":["../src/CreateSandboxHttp.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,gCAAgC,CAAC;AAE5D,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,aAAa,EAA0C,MAAM,oBAAoB,CAAC;AAC3F,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACzE,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAI9E;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,KAAK,CAAC,MAAM,CAC3C,aAAa,EACb,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;IAClB,OAAO,MAAM,CAAC,EAAE,CAAC,mBAAmB,CAAC,CAAC,QAAQ,CAAC,EAAE,IAAkB;QACjE,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,OAAO,CAAC;QAC5B,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,aAAa,CAAC;QACnC,6EAA6E;QAC7E,MAAM,MAAM,GACV,IAAI,KAAK,SAAS;YAChB,CAAC,CAAC,SAAS;YACX,CAAC,CAAC,KAAK,CAAC,CAAE,IAAI,CAAC,UAA2C,CAAC,QAAQ,EAAE,CAAC;QAC1E,2EAA2E;QAC3E,MAAM,UAAU,GACd,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C,GAAG,CAAC,CAAC;YACzB,CAAC,CAAC;YACF,IAAI,EAAE,CAAC,SAAS,EAAE,EAAE,CAClB,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,aAAa,CAAC,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,IAAI,CACpE,MAAM,CAAC,MAAM,EACb,MAAM,CAAC,QAAQ,CAAC,UAAU,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAC/C;YACH,OAAO,EAAE,CAAC,UAAU,EAAE,EAAE,CACtB,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,oBAAoB,CAAC,EAAE,WAAW,EAAE,CAAC,GAAG,UAAU,CAAC,EAAE,CAAC,CAAC;SACnF,CAAC;QACF,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CACH,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import * as Binding from "alchemy/Binding";
|
|
2
|
+
import type { RuntimeContext } from "alchemy/RuntimeContext";
|
|
3
|
+
import type * as Effect from "effect/Effect";
|
|
4
|
+
import type * as Redacted from "effect/Redacted";
|
|
5
|
+
import type { E2BError } from "./SandboxClient.ts";
|
|
6
|
+
import type { SecretAttributes } from "./Secret.ts";
|
|
7
|
+
/** A secret as E2B reports it: never its value. `ref` is the egress placeholder. */
|
|
8
|
+
export type SecretInfo = SecretAttributes;
|
|
9
|
+
/** E2B secrets by name: store, look up, list and delete them. */
|
|
10
|
+
export interface SecretsClient {
|
|
11
|
+
/**
|
|
12
|
+
* Stores a value under a name: creates the secret, or adds a new version
|
|
13
|
+
* of an existing one. Returns its `ref` to use in sandbox network rules.
|
|
14
|
+
*/
|
|
15
|
+
put(name: string, value: Redacted.Redacted<string>, options?: {
|
|
16
|
+
readonly metadata?: Readonly<Record<string, string>>;
|
|
17
|
+
}): Effect.Effect<SecretInfo, E2BError, RuntimeContext>;
|
|
18
|
+
/** The secret with this name or id, or `undefined`. */
|
|
19
|
+
get(nameOrId: string): Effect.Effect<SecretInfo | undefined, E2BError, RuntimeContext>;
|
|
20
|
+
/** The secrets this host created. */
|
|
21
|
+
list(): Effect.Effect<ReadonlyArray<SecretInfo>, E2BError, RuntimeContext>;
|
|
22
|
+
/** Deletes a secret. Deleting one that is gone succeeds. */
|
|
23
|
+
delete(nameOrId: string): Effect.Effect<void, E2BError, RuntimeContext>;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Store per-user credentials as E2B secrets at runtime, and reference them
|
|
27
|
+
* from a sandbox's network rules so the sandbox never sees the value.
|
|
28
|
+
*
|
|
29
|
+
* Secrets created at run time are tagged with the stack, stage and binding
|
|
30
|
+
* (`alchemy::stack`, `alchemy::stage`, `alchemy::id` in their E2B metadata)
|
|
31
|
+
* and are not deleted when the stack is destroyed. List them by those tags
|
|
32
|
+
* to clean them up: `secrets.list()` returns the ones this binding stored.
|
|
33
|
+
* Metadata you pass to `put` merges underneath; it never replaces the
|
|
34
|
+
* `alchemy::*` keys.
|
|
35
|
+
*
|
|
36
|
+
* ### Per-user credentials at egress
|
|
37
|
+
* **Example:** A user's GitHub token, injected into their sandbox's GitHub calls
|
|
38
|
+
* ```typescript
|
|
39
|
+
* const secrets = yield* E2B.CreateSecret();
|
|
40
|
+
* const sandboxes = yield* E2B.CreateSandbox(Agent);
|
|
41
|
+
* // in fetch:
|
|
42
|
+
* const github = yield* secrets.put(`github-${user}`, Redacted.make(token));
|
|
43
|
+
* const sandbox = yield* sandboxes.create({
|
|
44
|
+
* network: {
|
|
45
|
+
* allowOut: ["api.github.com"],
|
|
46
|
+
* rules: { "api.github.com": [{ transform: { headers: { Authorization: `Bearer ${github.ref}` } } }] },
|
|
47
|
+
* },
|
|
48
|
+
* });
|
|
49
|
+
* ```
|
|
50
|
+
*
|
|
51
|
+
* @binding
|
|
52
|
+
* @product Secret
|
|
53
|
+
*/
|
|
54
|
+
export interface CreateSecret extends Binding.Service<CreateSecret, "E2B.CreateSecret", () => Effect.Effect<SecretsClient>> {
|
|
55
|
+
}
|
|
56
|
+
export declare const CreateSecret: CreateSecret;
|
|
57
|
+
//# sourceMappingURL=CreateSecret.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CreateSecret.d.ts","sources":["../src/CreateSecret.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,iBAAiB,CAAC;AAC3C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,KAAK,KAAK,MAAM,MAAM,eAAe,CAAC;AAC7C,OAAO,KAAK,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEpD,oFAAoF;AACpF,MAAM,MAAM,UAAU,GAAG,gBAAgB,CAAC;AAE1C,iEAAiE;AACjE,MAAM,WAAW,aAAa;IAC5B;;;OAGG;IACH,GAAG,CACD,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,EAChC,OAAO,CAAC,EAAE;QAAE,QAAQ,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA;KAAE,GACjE,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,QAAQ,EAAE,cAAc,CAAC,CAAC;IACvD,uDAAuD;IACvD,GAAG,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,UAAU,GAAG,SAAS,EAAE,QAAQ,EAAE,cAAc,CAAC,CAAC;IACvF,qCAAqC;IACrC,IAAI,IAAI,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,UAAU,CAAC,EAAE,QAAQ,EAAE,cAAc,CAAC,CAAC;IAC3E,4DAA4D;IAC5D,MAAM,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,QAAQ,EAAE,cAAc,CAAC,CAAC;CACzE;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,WAAW,YAAa,SAAQ,OAAO,CAAC,OAAO,CACnD,YAAY,EACZ,kBAAkB,EAClB,MAAM,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,CACnC;CAAG;AAEJ,eAAO,MAAM,YAAY,cAAoD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CreateSecret.js","sources":["../src/CreateSecret.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,iBAAiB,CAAC;AAgE3C,MAAM,CAAC,MAAM,YAAY,GAAG,OAAO,CAAC,OAAO,CAAe,kBAAkB,CAAC,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import * as Layer from "effect/Layer";
|
|
2
|
+
import { CreateSecret } from "./CreateSecret.ts";
|
|
3
|
+
/**
|
|
4
|
+
* HTTP implementation of {@link CreateSecret}. Works on any host.
|
|
5
|
+
*
|
|
6
|
+
* ### Provide the layer
|
|
7
|
+
* **Example:** On a Worker
|
|
8
|
+
* ```typescript
|
|
9
|
+
* Effect.gen(function* () {
|
|
10
|
+
* const secrets = yield* E2B.CreateSecret();
|
|
11
|
+
* // ...
|
|
12
|
+
* }).pipe(Effect.provide(E2B.CreateSecretHttp))
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* @layer
|
|
16
|
+
* @product Secret
|
|
17
|
+
* @provides E2B.CreateSecret
|
|
18
|
+
*/
|
|
19
|
+
export declare const CreateSecretHttp: Layer.Layer<CreateSecret, never, never>;
|
|
20
|
+
//# sourceMappingURL=CreateSecretHttp.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CreateSecretHttp.d.ts","sources":["../src/CreateSecretHttp.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AAEtC,OAAO,EAAE,YAAY,EAAsB,MAAM,mBAAmB,CAAC;AAKrE;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,gBAAgB,yCAoE5B,CAAC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import * as secrets from "@distilled.cloud/e2b/secrets";
|
|
2
|
+
import * as Effect from "effect/Effect";
|
|
3
|
+
import * as Layer from "effect/Layer";
|
|
4
|
+
import * as Stream from "effect/Stream";
|
|
5
|
+
import { CreateSecret } from "./CreateSecret.js";
|
|
6
|
+
import { bindE2B, bindOwnerTags } from "./E2BBindings.js";
|
|
7
|
+
import { E2BUnexpectedResponse } from "./Errors.js";
|
|
8
|
+
import { toSecretAttributes } from "./Secret.js";
|
|
9
|
+
/**
|
|
10
|
+
* HTTP implementation of {@link CreateSecret}. Works on any host.
|
|
11
|
+
*
|
|
12
|
+
* ### Provide the layer
|
|
13
|
+
* **Example:** On a Worker
|
|
14
|
+
* ```typescript
|
|
15
|
+
* Effect.gen(function* () {
|
|
16
|
+
* const secrets = yield* E2B.CreateSecret();
|
|
17
|
+
* // ...
|
|
18
|
+
* }).pipe(Effect.provide(E2B.CreateSecretHttp))
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* @layer
|
|
22
|
+
* @product Secret
|
|
23
|
+
* @provides E2B.CreateSecret
|
|
24
|
+
*/
|
|
25
|
+
export const CreateSecretHttp = Layer.effect(CreateSecret, Effect.gen(function* () {
|
|
26
|
+
return Effect.fn("E2B.CreateSecret")(function* () {
|
|
27
|
+
const auth = yield* bindE2B;
|
|
28
|
+
const owner = yield* bindOwnerTags;
|
|
29
|
+
const get = (nameOrId) => auth.authorize(secrets.getSecret({ secretID: nameOrId.toLowerCase() })).pipe(Effect.map((secret) => secret), Effect.catchTag("NotFound", () => Effect.undefined));
|
|
30
|
+
const client = {
|
|
31
|
+
put: Effect.fn("E2B.CreateSecret.put")(function* (name, value, putOptions) {
|
|
32
|
+
const metadata = { ...putOptions?.metadata, ...(yield* owner) };
|
|
33
|
+
const existing = yield* get(name);
|
|
34
|
+
const stored = existing !== undefined
|
|
35
|
+
? yield* auth.authorize(secrets.updateSecret({ secretID: existing.secretID, value, metadata }))
|
|
36
|
+
: yield* auth.authorize(secrets.createSecret({ name, value, metadata })).pipe(
|
|
37
|
+
// A concurrent put created it first: add our version.
|
|
38
|
+
Effect.catchTag("Conflict", () => Effect.gen(function* () {
|
|
39
|
+
const raced = yield* get(name);
|
|
40
|
+
if (raced === undefined) {
|
|
41
|
+
return yield* new E2BUnexpectedResponse({
|
|
42
|
+
message: `E2B secret ${name} vanished during put`,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
return yield* auth.authorize(secrets.updateSecret({ secretID: raced.secretID, value, metadata }));
|
|
46
|
+
})));
|
|
47
|
+
return toSecretAttributes(stored);
|
|
48
|
+
}),
|
|
49
|
+
get: (nameOrId) => get(nameOrId).pipe(Effect.map((secret) => (secret === undefined ? undefined : toSecretAttributes(secret)))),
|
|
50
|
+
list: Effect.fn("E2B.CreateSecret.list")(function* () {
|
|
51
|
+
const owned = yield* owner;
|
|
52
|
+
const all = yield* auth.authorize(Stream.runCollect(secrets.listSecrets.items({ limit: 100 })));
|
|
53
|
+
return Array.from(all)
|
|
54
|
+
.filter((secret) => Object.entries(owned).every(([key, value]) => secret.metadata[key] === value))
|
|
55
|
+
.map(toSecretAttributes);
|
|
56
|
+
}),
|
|
57
|
+
delete: (nameOrId) => Effect.flatMap(get(nameOrId), (secret) => secret === undefined
|
|
58
|
+
? Effect.void
|
|
59
|
+
: auth.authorize(secrets.deleteSecret({ secretID: secret.secretID })).pipe(Effect.asVoid, Effect.catchTag("NotFound", () => Effect.void))),
|
|
60
|
+
};
|
|
61
|
+
return client;
|
|
62
|
+
});
|
|
63
|
+
}));
|
|
64
|
+
//# sourceMappingURL=CreateSecretHttp.js.map
|
|
@@ -0,0 +1 @@
|
|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MAAM,EACb,MAAM,CAAC,QAAQ,CAAC,UAAU,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAC/C,CACN;SACJ,CAAC;QACF,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CACH,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type * as sandboxes from "@distilled.cloud/e2b/sandboxes";
|
|
2
|
+
import type * as snapshots from "@distilled.cloud/e2b/snapshots";
|
|
3
|
+
import * as Binding from "alchemy/Binding";
|
|
4
|
+
import type { RuntimeContext } from "alchemy/RuntimeContext";
|
|
5
|
+
import type * as Effect from "effect/Effect";
|
|
6
|
+
import type { SnapshotSetupFailed } from "./Errors.ts";
|
|
7
|
+
import type { SnapshotSetup } from "./internal/SnapshotBuild.ts";
|
|
8
|
+
import type { E2BError } from "./SandboxClient.ts";
|
|
9
|
+
export type { SnapshotSetup } from "./internal/SnapshotBuild.ts";
|
|
10
|
+
/** E2B snapshots: take, list and delete them at runtime. */
|
|
11
|
+
export interface SnapshotsClient {
|
|
12
|
+
/**
|
|
13
|
+
* Boots `template`, runs the setup commands, snapshots it under `name` and
|
|
14
|
+
* kills the setup sandbox. Snapshotting under an existing name adds a new
|
|
15
|
+
* version. Use `sandbox.snapshot()` to snapshot a sandbox you already have.
|
|
16
|
+
*/
|
|
17
|
+
create(name: string, setup: SnapshotSetup): Effect.Effect<sandboxes.SnapshotInfo, E2BError | SnapshotSetupFailed, RuntimeContext>;
|
|
18
|
+
/** Snapshots, filtered by source sandbox or name. */
|
|
19
|
+
list(options?: Omit<snapshots.ListSnapshotsRequest, "nextToken">): Effect.Effect<ReadonlyArray<snapshots.SnapshotInfo>, E2BError, RuntimeContext>;
|
|
20
|
+
/** Deletes a snapshot (and every version of it). Deleting one that is gone succeeds. */
|
|
21
|
+
delete(name: string): Effect.Effect<void, E2BError, RuntimeContext>;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Take and manage E2B snapshots at runtime: a warm base per repository or
|
|
25
|
+
* per customer, created on demand and forked into sandboxes.
|
|
26
|
+
*
|
|
27
|
+
* Snapshots taken at runtime carry no metadata, so they are not deleted when
|
|
28
|
+
* the host is destroyed. Delete them with `delete` when their owner goes
|
|
29
|
+
* away.
|
|
30
|
+
*
|
|
31
|
+
* ### Warm bases at runtime
|
|
32
|
+
* **Example:** A warm base per repository
|
|
33
|
+
* ```typescript
|
|
34
|
+
* const snapshots = yield* E2B.CreateSnapshot();
|
|
35
|
+
* const sandboxes = yield* E2B.CreateSandbox();
|
|
36
|
+
* // in fetch:
|
|
37
|
+
* const [existing] = yield* snapshots.list({ name: `warm-${slug}` });
|
|
38
|
+
* const base =
|
|
39
|
+
* existing ??
|
|
40
|
+
* (yield* snapshots.create(`warm-${slug}`, {
|
|
41
|
+
* template: "node-22",
|
|
42
|
+
* run: [`git clone https://github.com/${repo} repo`, "cd repo && npm ci"],
|
|
43
|
+
* }));
|
|
44
|
+
* const sandbox = yield* sandboxes.create({ templateID: base.snapshotID });
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* @binding
|
|
48
|
+
* @product Snapshot
|
|
49
|
+
*/
|
|
50
|
+
export interface CreateSnapshot extends Binding.Service<CreateSnapshot, "E2B.CreateSnapshot", () => Effect.Effect<SnapshotsClient>> {
|
|
51
|
+
}
|
|
52
|
+
export declare const CreateSnapshot: CreateSnapshot;
|
|
53
|
+
//# sourceMappingURL=CreateSnapshot.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CreateSnapshot.d.ts","sources":["../src/CreateSnapshot.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,SAAS,MAAM,gCAAgC,CAAC;AACjE,OAAO,KAAK,KAAK,SAAS,MAAM,gCAAgC,CAAC;AACjE,OAAO,KAAK,OAAO,MAAM,iBAAiB,CAAC;AAC3C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CA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,CAAC,OAAO,CAAiB,oBAAoB,CAAC,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import * as Layer from "effect/Layer";
|
|
2
|
+
import { CreateSnapshot } from "./CreateSnapshot.ts";
|
|
3
|
+
/**
|
|
4
|
+
* HTTP implementation of {@link CreateSnapshot}. Works on any host.
|
|
5
|
+
*
|
|
6
|
+
* ### Provide the layer
|
|
7
|
+
* **Example:** On a Worker
|
|
8
|
+
* ```typescript
|
|
9
|
+
* Effect.gen(function* () {
|
|
10
|
+
* const snapshots = yield* E2B.CreateSnapshot();
|
|
11
|
+
* // ...
|
|
12
|
+
* }).pipe(Effect.provide(E2B.CreateSnapshotHttp))
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* @layer
|
|
16
|
+
* @product Snapshot
|
|
17
|
+
* @provides E2B.CreateSnapshot
|
|
18
|
+
*/
|
|
19
|
+
export declare const CreateSnapshotHttp: Layer.Layer<CreateSnapshot, never, never>;
|
|
20
|
+
//# sourceMappingURL=CreateSnapshotHttp.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CreateSnapshotHttp.d.ts","sources":["../src/CreateSnapshotHttp.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AAEtC,OAAO,EAAE,cAAc,EAAwB,MAAM,qBAAqB,CAAC;AAI3E;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,kBAAkB,2CA6B9B,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import * as snapshots from "@distilled.cloud/e2b/snapshots";
|
|
2
|
+
import * as templates from "@distilled.cloud/e2b/templates";
|
|
3
|
+
import * as Effect from "effect/Effect";
|
|
4
|
+
import * as Layer from "effect/Layer";
|
|
5
|
+
import * as Stream from "effect/Stream";
|
|
6
|
+
import { CreateSnapshot } from "./CreateSnapshot.js";
|
|
7
|
+
import { bindE2B } from "./E2BBindings.js";
|
|
8
|
+
import { takeSnapshot } from "./internal/SnapshotBuild.js";
|
|
9
|
+
/**
|
|
10
|
+
* HTTP implementation of {@link CreateSnapshot}. Works on any host.
|
|
11
|
+
*
|
|
12
|
+
* ### Provide the layer
|
|
13
|
+
* **Example:** On a Worker
|
|
14
|
+
* ```typescript
|
|
15
|
+
* Effect.gen(function* () {
|
|
16
|
+
* const snapshots = yield* E2B.CreateSnapshot();
|
|
17
|
+
* // ...
|
|
18
|
+
* }).pipe(Effect.provide(E2B.CreateSnapshotHttp))
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* @layer
|
|
22
|
+
* @product Snapshot
|
|
23
|
+
* @provides E2B.CreateSnapshot
|
|
24
|
+
*/
|
|
25
|
+
export const CreateSnapshotHttp = Layer.succeed(CreateSnapshot, Effect.fn("E2B.CreateSnapshot")(function* () {
|
|
26
|
+
const auth = yield* bindE2B;
|
|
27
|
+
const client = {
|
|
28
|
+
create: (name, setup) => auth.authorize(takeSnapshot(name, setup)),
|
|
29
|
+
list: (options) => auth
|
|
30
|
+
.authorize(Stream.runCollect(snapshots.listSnapshots.items({ ...options })))
|
|
31
|
+
.pipe(Effect.map((all) => Array.from(all))),
|
|
32
|
+
// A snapshot is stored as a template under its name.
|
|
33
|
+
delete: (name) => auth
|
|
34
|
+
.authorize(templates
|
|
35
|
+
.getTemplateByAlias({ alias: name })
|
|
36
|
+
.pipe(Effect.flatMap((alias) => templates.deleteTemplate({ templateID: alias.templateID }))))
|
|
37
|
+
.pipe(Effect.asVoid, Effect.catchTag("NotFound", () => Effect.void)),
|
|
38
|
+
};
|
|
39
|
+
return client;
|
|
40
|
+
}));
|
|
41
|
+
//# sourceMappingURL=CreateSnapshotHttp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CreateSnapshotHttp.js","sources":["../src/CreateSnapshotHttp.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,gCAAgC,CAAC;AAC5D,OAAO,KAAK,SA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