@e2b/convex

中文文档
0.1.1发布于 2026/09/14MITTypeScriptES Module构建来源已验证近 30 天下载 1.6万

E2B sandboxes for Convex agent applications

原始使用文档
文档目录5 节
  1. Install
  2. Run a command
  3. Integrations
  4. Defaults and limits
  5. Status

@e2b/convex

Persistent E2B sandboxes for Convex applications and AI agents.

@e2b/convex is a tableless Convex component with a small V8-compatible E2B client. It gives Convex actions sandbox lifecycle, commands, bounded file operations, preview hosts, Convex Agent tools, and plain AI SDK tools without shipping the full Node-oriented E2B SDK into the Convex runtime.

Pre-1.0: validate the package against your E2B template and network policy before production use.

Install

npm install @e2b/convex
npx convex env set E2B_API_KEY e2b_your_key

Register the component and bind the secret in your Convex app:

// convex/convex.config.ts
import e2b from "@e2b/convex/convex.config.js";
import { defineApp } from "convex/server";
import { v } from "convex/values";

const app = defineApp({ env: { E2B_API_KEY: v.string() } });
app.use(e2b, { env: { E2B_API_KEY: app.env.E2B_API_KEY } });

export default app;

Run a command

Create the client in a Convex action and identify the sandbox with an application-owned scope and key:

// convex/sandbox.ts
import { E2B } from "@e2b/convex";
import { v } from "convex/values";
import { components } from "./_generated/api";
import { action } from "./_generated/server";

const sandboxes = new E2B(components.e2b, {
  template: "base",
  timeoutMs: 10 * 60_000,
});

export const run = action({
  args: { userId: v.string(), sessionId: v.string(), command: v.string() },
  handler: async (ctx, args) => {
    const identity = { scope: args.userId, key: args.sessionId };
    const sandbox = await sandboxes.getOrCreate(ctx, identity);

    return sandboxes.runCommand(ctx, {
      ...identity,
      sandboxId: sandbox.sandboxId,
      command: args.command,
    });
  },
});

Calls with the same scope and key reuse the same running or paused sandbox. Resolve it once before parallel work and pass sandboxId to subsequent operations.

Integrations

  • Minimal API: lifecycle, shell commands, files, directories, and preview hosts.
  • Convex Agent: createAgentTools(sandboxes, ...) from @e2b/convex/agent creates thread-aware tools with optional approval rules. Requires @convex-dev/agent and ai.
  • AI SDK: createAiSdkTools(sandboxes, ctx, ...) from @e2b/convex/ai creates standard AI SDK tools inside any Convex action. Requires ai.

The core package has no runtime dependency on either; install them only for the integration you use.

Start with the getting-started guide, then use the copy-paste cookbook. The complete local app in example includes an xterm.js terminal and a realtime agent chat with visible tool calls.

Defaults and limits

  • Sandboxes pause on timeout and are rediscovered through namespaced E2B metadata. Any operation on a paused sandbox resumes it, which restarts billing.
  • Every operation resolves the sandbox first (getInfo + connect, or a metadata list when sandboxId is absent), adding roughly a second per call.
  • Scope and key values are hashed before entering E2B metadata.
  • Command output is bounded to 32 KiB per stream by default.
  • Command output and individual file reads are capped at 1 MiB.
  • File reads default to 64 KiB; writes are capped at 4 MiB.
  • File tools are restricted to /home/user and /tmp unless configured otherwise.
  • getHost is not exposed to an agent unless explicitly enabled.
  • Every E2B request is tagged with e2b-convex/<version> for integration attribution.

See security, operations, and architecture before deploying an agent that executes untrusted instructions.

Status

The package uses E2B's public APIs and includes only the Process and Filesystem protocol descriptors required by the component. The pinned e2b package is a development-only protocol source. CI rejects Node built-ins or full-SDK imports in the emitted Convex runtime and a scheduled real-service test watches for protocol drift.

MIT

版本与发布记录

@e2b/convex 共发布 2 个版本,首次发布于 2026/09/14;过去 12 个月发布了 2 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.1.1latest2026/09/141 个月前
0.1.02026/09/141 个月前

关于 @e2b/convex 的常见问题

@e2b/convex 是什么?

E2B sandboxes for Convex agent applications

如何安装 @e2b/convex?

在项目目录运行 npm install @e2b/convex,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:convex(^1.45.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@e2b/convex 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@e2b/convex 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@e2b/convex 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=20。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@e2b/convex 可以商用吗?

@e2b/convex 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@e2b/convex 的下载量有多少?

根据 npm 官方下载统计,@e2b/convex 在 2026/10/13 – 2026/11/11 这 30 天内被下载 16,406 次,日均约 547 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@e2b/convex 还在维护吗?

最新版本 0.1.1 发布于 2026/09/14(1 个月前);至今共发布 2 个版本,其中过去 12 个月发布了 2 个;首次发布于 2026/09/14。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。