@denieler/e2b-codex 0.1.1 → 0.1.3

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 CHANGED
@@ -1,11 +1,9 @@
1
- # @denieler/e2e-codex
1
+ # @denieler/e2b-codex
2
2
 
3
3
  Use a shared E2B template with Codex preinstalled, then create fresh sandboxes from that template and talk to `codex app-server` over websocket.
4
4
 
5
5
  ![e2b-codex banner](https://raw.githubusercontent.com/denieler/e2b-codex/main/assets/e2b-codex-banner.svg)
6
6
 
7
- ![e2b-codex banner](./assets/e2b-codex-banner.svg)
8
-
9
7
  This project covers two jobs:
10
8
 
11
9
  - runtime use: create a sandbox, connect to Codex, send prompts, continue conversations
@@ -16,7 +14,7 @@ This project covers two jobs:
16
14
  Install the package:
17
15
 
18
16
  ```bash
19
- npm install @denieler/e2e-codex
17
+ npm install @denieler/e2b-codex
20
18
  ```
21
19
 
22
20
  ### What you need
@@ -47,7 +45,7 @@ What this does:
47
45
  ### Create a ready sandbox in code
48
46
 
49
47
  ```ts
50
- import { createReadyCodexSandbox } from "@denieler/e2e-codex";
48
+ import { createReadyCodexSandbox } from "@denieler/e2b-codex";
51
49
 
52
50
  const ready = await createReadyCodexSandbox({
53
51
  e2bApiKey: process.env.E2B_API_KEY!,
@@ -64,10 +62,25 @@ The returned object includes:
64
62
  - `authToken`
65
63
  - `workspaceRoot`
66
64
 
65
+ ### Connect to an existing sandbox in code
66
+
67
+ ```ts
68
+ import { connectCodexSandbox } from "@denieler/e2b-codex";
69
+
70
+ const ready = await connectCodexSandbox({
71
+ e2bApiKey: process.env.E2B_API_KEY!,
72
+ sandboxId: "sandbox-id",
73
+ openAiApiKey: process.env.OPENAI_API_KEY!,
74
+ userId: "user-123",
75
+ });
76
+ ```
77
+
78
+ Use this when you already persisted `sandboxId` and want to reconnect to the same sandbox instead of creating a new one.
79
+
67
80
  ### Connect to Codex over websocket
68
81
 
69
82
  ```ts
70
- import { connectCodexClient } from "@denieler/e2e-codex";
83
+ import { connectCodexClient } from "@denieler/e2b-codex";
71
84
 
72
85
  const client = await connectCodexClient(ready);
73
86
  ```
@@ -115,7 +128,7 @@ If your websocket connection drops, reconnect using the same `websocketUrl` and
115
128
  If you want one fresh sandbox and one prompt, use:
116
129
 
117
130
  ```ts
118
- import { createReadyCodexSandbox, runPrompt } from "@denieler/e2e-codex";
131
+ import { createReadyCodexSandbox, runPrompt } from "@denieler/e2b-codex";
119
132
 
120
133
  const sandbox = await createReadyCodexSandbox({
121
134
  e2bApiKey: process.env.E2B_API_KEY!,
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { CodexAppServerClient } from "./codex-app-server.js";
2
2
  export { loadLocalEnvFile, requireEnvVar } from "./env.js";
3
3
  export { template } from "./template.js";
4
- export { connectCodexClient, createReadyCodexSandbox, runPrompt, } from "./sandbox.js";
5
- export type { CreateCodexSandboxOptions, ReadyCodexSandbox } from "./sandbox.js";
4
+ export { connectCodexSandbox, connectCodexClient, createReadyCodexSandbox, runPrompt, } from "./sandbox.js";
5
+ export type { CodexSandboxOptions, ConnectCodexSandboxOptions, CreateCodexSandboxOptions, ReadyCodexSandbox, } from "./sandbox.js";
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
1
  export { CodexAppServerClient } from "./codex-app-server.js";
2
2
  export { loadLocalEnvFile, requireEnvVar } from "./env.js";
3
3
  export { template } from "./template.js";
4
- export { connectCodexClient, createReadyCodexSandbox, runPrompt, } from "./sandbox.js";
4
+ export { connectCodexSandbox, connectCodexClient, createReadyCodexSandbox, runPrompt, } from "./sandbox.js";
package/dist/sandbox.d.ts CHANGED
@@ -1,8 +1,7 @@
1
1
  import { Sandbox } from "e2b";
2
2
  import { CodexAppServerClient } from "./codex-app-server.js";
3
- export type CreateCodexSandboxOptions = {
3
+ export type CodexSandboxOptions = {
4
4
  e2bApiKey: string;
5
- templateId: string;
6
5
  openAiApiKey: string;
7
6
  userId: string;
8
7
  timeoutMs?: number;
@@ -11,6 +10,12 @@ export type CreateCodexSandboxOptions = {
11
10
  workspaceRoot?: string;
12
11
  metadata?: Record<string, string>;
13
12
  };
13
+ export type CreateCodexSandboxOptions = CodexSandboxOptions & {
14
+ templateId: string;
15
+ };
16
+ export type ConnectCodexSandboxOptions = Omit<CodexSandboxOptions, "allowInternetAccess" | "metadata"> & {
17
+ sandboxId: string;
18
+ };
14
19
  export type ReadyCodexSandbox = {
15
20
  sandbox: Sandbox;
16
21
  sandboxId: string;
@@ -20,6 +25,7 @@ export type ReadyCodexSandbox = {
20
25
  workspaceRoot: string;
21
26
  };
22
27
  export declare function createReadyCodexSandbox(options: CreateCodexSandboxOptions): Promise<ReadyCodexSandbox>;
28
+ export declare function connectCodexSandbox(options: ConnectCodexSandboxOptions): Promise<ReadyCodexSandbox>;
23
29
  export declare function connectCodexClient(readySandbox: Pick<ReadyCodexSandbox, "websocketUrl" | "authToken">): Promise<CodexAppServerClient>;
24
30
  export declare function runPrompt(options: {
25
31
  sandbox: ReadyCodexSandbox;
package/dist/sandbox.js CHANGED
@@ -73,6 +73,30 @@ export async function createReadyCodexSandbox(options) {
73
73
  workspaceRoot,
74
74
  };
75
75
  }
76
+ export async function connectCodexSandbox(options) {
77
+ const port = options.port ?? 4571;
78
+ const workspaceRoot = options.workspaceRoot ?? "/workspace";
79
+ const sandbox = await Sandbox.connect(options.sandboxId, {
80
+ apiKey: options.e2bApiKey,
81
+ });
82
+ if (options.timeoutMs) {
83
+ await sandbox.setTimeout(options.timeoutMs);
84
+ }
85
+ await ensureAppServerRunning(sandbox, {
86
+ openAiApiKey: options.openAiApiKey,
87
+ port,
88
+ workspaceRoot,
89
+ userId: options.userId,
90
+ });
91
+ return {
92
+ sandbox,
93
+ sandboxId: sandbox.sandboxId,
94
+ websocketUrl: `wss://${sandbox.getHost(port)}`,
95
+ authToken: createAppServerToken(options.userId),
96
+ port,
97
+ workspaceRoot,
98
+ };
99
+ }
76
100
  export async function connectCodexClient(readySandbox) {
77
101
  let lastError = null;
78
102
  for (let attempt = 0; attempt < 20; attempt += 1) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@denieler/e2b-codex",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "Build and use E2B sandboxes with Codex preinstalled and codex app-server ready over websocket.",
5
5
  "license": "MIT",
6
6
  "type": "module",