refactor(e2b): keep code runtime host-local

This commit is contained in:
Tianyi Cui
2026-07-30 14:50:47 +08:00
parent 258bd4456b
commit 26b18ba189
19 changed files with 29 additions and 111 deletions

View File

@@ -2,5 +2,5 @@
# side as of the last confirmed-consistent state. Both languages carry equal authority;
# after editing either side, bring the other along and re-record with:
# pnpm run verify-translation-pairing --write packages/README.md
README.md: 1fd0c9c2385f3169791a28f3ef50bb42792760af
README.zh.md: f9f7d5ae8839ea7033a349ac7a0083a97780a21c
README.md: a9a121d0cb13cd5e2148da8d754967359be06bab
README.zh.md: c6500ebb2abce14fabf68b79ec20f5c23cf5d5f7

View File

@@ -2,5 +2,5 @@
# side as of the last confirmed-consistent state. Both languages carry equal authority;
# after editing either side, bring the other along and re-record with:
# pnpm run verify-translation-pairing --write packages/e2b/README.md
README.md: 3c85b2790d3414af73625e65732df58ff9fec566
README.zh.md: a759539fc054dd68e75f3c7660ccc3b762985af5
README.md: adc002649e44faefd2f6bd84b7b45fb9fc6fa41d
README.zh.md: d941de8da2cb831a69a165c86a825def68c2b319

View File

@@ -10,6 +10,6 @@ An experimental provider-composition POC that places one filesystem/process exec
| [`fs-e2b`](fs-e2b/README.md) (`@deepseek-ai/dsh-fs-e2b`) | `ctx.fs` | Implement the filesystem seam over E2B Filesystem APIs |
| [`subprocess-e2b`](subprocess-e2b/README.md) (`@deepseek-ai/dsh-subprocess-e2b`) | `ctx.subprocess` | Implement executable lookup, managed process groups and stdio, remote spill files, and terminal sessions over E2B Commands and PTY APIs |
The existing [`dsh-bash-local`](../bash/bash-local/README.md), [`dsh-pty-local`](../pty/pty-local/README.md), [`dsh-lsp-local`](../lsp/lsp-local/README.md), and [`dsh-code-runtime-subprocess`](../code-runtime/code-runtime-subprocess/README.md) need no E2B-specific forks. They delegate every execution-world operation to `ctx.fs` and `ctx.subprocess`, so mounting the two E2B adapters places their mutable work in the same sandbox.
The existing [`dsh-bash-local`](../bash/bash-local/README.md), [`dsh-pty-local`](../pty/pty-local/README.md), and [`dsh-lsp-local`](../lsp/lsp-local/README.md) need no E2B-specific forks. They delegate every execution-world operation to `ctx.fs` and `ctx.subprocess`, so mounting the two E2B adapters places their mutable work in the same sandbox. The worker-backed Code Runtime remains host-local and reaches that world only through the tools its programs call.
This boundary does not move the harness process, Cordis objects, model calls, agent/session state, session persistence, skills, higher-level protocol state, or E2B SDK buffers. The [portable execution-world decision](../../.agents/notes/implemented/architecture/2026-07-28-portable-execution-world-consumers.md) owns both the generic composition and this POC boundary.

View File

@@ -10,6 +10,6 @@
| [`fs-e2b`](fs-e2b/README.md)`@deepseek-ai/dsh-fs-e2b` | `ctx.fs` | 通过 E2B Filesystem API 实现文件系统 seam |
| [`subprocess-e2b`](subprocess-e2b/README.md)`@deepseek-ai/dsh-subprocess-e2b` | `ctx.subprocess` | 通过 E2B Commands 与 PTY API 实现可执行文件查找、受管进程组与 stdio、远程 spill 文件及终端会话 |
现有的 [`dsh-bash-local`](../bash/bash-local/README.md)、[`dsh-pty-local`](../pty/pty-local/README.md)[`dsh-lsp-local`](../lsp/lsp-local/README.md) 及 [`dsh-code-runtime-subprocess`](../code-runtime/code-runtime-subprocess/README.md) 无需 E2B 专用 fork。它们把执行环境中的所有操作委托给 `ctx.fs``ctx.subprocess`,因此挂载这两个 E2B 适配器后,它们执行的可变操作都发生在同一个沙箱内。
现有的 [`dsh-bash-local`](../bash/bash-local/README.md)、[`dsh-pty-local`](../pty/pty-local/README.md)[`dsh-lsp-local`](../lsp/lsp-local/README.md) 无需 E2B 专用 fork。它们把执行环境中的所有操作委托给 `ctx.fs``ctx.subprocess`,因此挂载这两个 E2B 适配器后,它们执行的可变操作都发生在同一个沙箱内。基于 worker 的代码运行时仍在宿主本地运行,只会通过其程序调用的工具触达该执行世界。
该边界不会迁移 harness 进程、Cordis 对象、模型调用、agent智能体会话状态、会话持久化、skill技能、更高层协议状态或 E2B SDK 缓冲。[可移植执行世界决策](../../.agents/notes/implemented/architecture/2026-07-28-portable-execution-world-consumers.md)同时界定通用组合和此 POC 边界。

View File

@@ -2,5 +2,5 @@
# side as of the last confirmed-consistent state. Both languages carry equal authority;
# after editing either side, bring the other along and re-record with:
# pnpm run verify-translation-pairing --write packages/e2b/e2b/README.md
README.md: 7ade7c3d6522d8fa6d54d7011766238451b17c9a
README.zh.md: b683f33d2211106cf422e780b2b37904b0c640ad
README.md: 52f99178ce8c06e61c13ea9364769ac887db4410
README.zh.md: 98ba7e79841f548ff6465fda4bc37170c17bc6e0

View File

@@ -38,7 +38,7 @@ No direct invalidation; this package does not contribute request tokens.
## Known Limitations and Deferred Work
- **This is not a whole-harness runtime** — Cordis services, agent/session state, session logs, LLM requests, skills, and SDK-side buffers stay in the host process.
- **This is not a whole-harness runtime** — Cordis services, the worker-backed Code Runtime, agent/session state, session logs, LLM requests, skills, and SDK-side buffers stay in the host process.
- **Sandbox state is ephemeral** — disposal and timeout delete the sandbox; reconnect, pause/leave retention, templates, volumes, and snapshots are outside this POC.
- **No deployment platform is configured** — network policy, host-workspace synchronization, and sandbox discovery are outside this POC.
- **`cwd` is a resolution convention, not containment** — adapters and commands can address other sandbox paths; E2B network access retains the base image's policy.

View File

@@ -38,7 +38,7 @@
## 已知限制与延后工作
- **这不是完整的 harness 运行时**Cordis 服务、agent智能体会话状态、会话日志、LLM大语言模型请求、skill技能和 SDK 侧缓冲仍留在宿主进程中。
- **这不是完整的 harness 运行时**Cordis 服务、基于 worker 的代码运行时、agent智能体会话状态、会话日志、LLM大语言模型请求、skill技能和 SDK 侧缓冲仍留在宿主进程中。
- **沙箱状态是短暂的**资源释放和超时都会删除沙箱重新连接、pause/leave 保留、模板、卷和快照均不在本 POC 范围内。
- **没有配置部署平台**:网络策略、宿主工作区同步和沙箱发现均不在本 POC 范围内。
- **`cwd` 是解析约定,而不是包含边界**适配器和命令可以访问沙箱中的其他路径E2B 网络访问也继续采用基础镜像的策略。

View File

@@ -57,7 +57,7 @@ describe.skipIf(!process.env.E2B_API_KEY)('E2B live Loader composition', () => {
const ptyFiber = await ctx.plugin(PtyService)
const subprocessFiber = await ctx.plugin(E2BSubprocessService)
const node = await ctx.subprocess.resolveExecutable('node')
const relativeNodePath = posix.relative(ctx.subprocess.cwd, posix.dirname(node)) || '.'
const relativeNodePath = posix.relative(ctx.e2b.cwd, posix.dirname(node)) || '.'
await expect(ctx.subprocess.resolveExecutable('node', { PATH: relativeNodePath })).resolves.toBe(node)
await expect(sandbox.files.read(profileLeakPath)).rejects.toBeInstanceOf(FileNotFoundError)
const environmentProbe = ctx.subprocess.spawn({
@@ -117,7 +117,7 @@ describe.skipIf(!process.env.E2B_API_KEY)('E2B live Loader composition', () => {
}
}, 70_000)
it('runs FS, Bash, PTY, LSP, and Code Runtime in one sandbox and deletes it', async () => {
it('runs FS, Bash, PTY, and LSP in one sandbox and deletes it', async () => {
const { stdout, stderr } = await runLoaderSmoke({
label: 'E2B composition',
tempDirPrefix: 'dsh-e2b-composition-',
@@ -157,9 +157,6 @@ describe.skipIf(!process.env.E2B_API_KEY)('E2B live Loader composition', () => {
interrupted: { sessionStatus: { kind: 'running' } },
treeCleanup: true,
},
descendantPipe: { value: true, logs: [] },
descendantCleanup: true,
lingeringCodeRunners: 0,
})
const terminalMotd = (output.terminal as { motd: string }).motd
expect(terminalMotd.length).toBeGreaterThan(0)
@@ -171,10 +168,6 @@ describe.skipIf(!process.env.E2B_API_KEY)('E2B live Loader composition', () => {
expect(['stdin_read', 'inferred_idle']).toContain(
(output.terminal as { interrupted: { waitReason: string } }).interrupted.waitReason,
)
expect(output.code).toEqual({
value: { doubled: 42, typed: true },
logs: ['remote-log 你好 42'],
})
const apiKey = process.env.E2B_API_KEY
if (apiKey === undefined) throw new Error('E2B_API_KEY disappeared during the live composition test')
await expect(Sandbox.getInfo(String(output.sandboxId), { apiKey })).rejects.toBeInstanceOf(SandboxNotFoundError)

View File

@@ -2,5 +2,5 @@
# side as of the last confirmed-consistent state. Both languages carry equal authority;
# after editing either side, bring the other along and re-record with:
# pnpm run verify-translation-pairing --write packages/e2b/subprocess-e2b/README.md
README.md: 3ddfe5bc47309ba56d3f8af7720fcbe71ec8a302
README.zh.md: c4db7bf8bb8a0f4b2f147dd22868978be5d1fcf4
README.md: 3bb9802c3afa41f3949fceeb73e76ea5cebce744
README.zh.md: 520f0ea1cde18ed523ba80015d3d4700730aba7a

View File

@@ -2,7 +2,7 @@
English | [中文](README.zh.md)
E2B implementation of the [`@deepseek-ai/dsh-subprocess`](../../subprocess/subprocess/README.md) seam. It has no config: load [`@deepseek-ai/dsh-e2b`](../e2b/README.md) first, then this service in place of `dsh-subprocess-local`. Existing Bash, PTY, LSP, and subprocess Code Runtime consumers then execute in the shared remote sandbox without E2B-specific capability packages.
E2B implementation of the [`@deepseek-ai/dsh-subprocess`](../../subprocess/subprocess/README.md) seam. It has no config: load [`@deepseek-ai/dsh-e2b`](../e2b/README.md) first, then this service in place of `dsh-subprocess-local`. Existing Bash, PTY, and LSP consumers then execute in the shared remote sandbox without E2B-specific capability packages.
## Behavior

View File

@@ -2,7 +2,7 @@
[English](README.md) | 中文
[`@deepseek-ai/dsh-subprocess`](../../subprocess/subprocess/README.md) seam 的 E2B 实现。它没有配置:先加载 [`@deepseek-ai/dsh-e2b`](../e2b/README.md),再用本服务取代 `dsh-subprocess-local`。现有的 Bash、PTY、LSP 以及使用 subprocess 的 Code Runtime 消费方随后会在共享远程沙箱中执行,无需 E2B 专用的功能包package
[`@deepseek-ai/dsh-subprocess`](../../subprocess/subprocess/README.md) seam 的 E2B 实现。它没有配置:先加载 [`@deepseek-ai/dsh-e2b`](../e2b/README.md),再用本服务取代 `dsh-subprocess-local`。现有的 Bash、PTY 和 LSP 消费方随后会在共享远程沙箱中执行,无需 E2B 专用的功能包package
## 行为

View File

@@ -31,17 +31,9 @@ export class E2BSubprocessService extends SubprocessService {
private readonly terminalSetups = new Map<Promise<void>, AbortController>()
private disposing = false
/** @inheritdoc */
readonly cwd: string
/** @inheritdoc */
readonly runtimeRoot: string
/** Create the E2B subprocess service and bind its disposal policy. */
constructor(ctx: Context) {
super(ctx)
this.cwd = ctx.e2b.cwd
this.runtimeRoot = ctx.e2b.runtimeRoot
ctx.effect(() => async () => {
this.disposing = true
for (const controller of this.terminalSetups.values()) {
@@ -89,14 +81,14 @@ export class E2BSubprocessService extends SubprocessService {
const prefix = path === undefined ? '' : `PATH=${quoteE2BShellArg(path)} `
const result = await sandbox.commands.run(
`${prefix}command -v -- ${quoteE2BShellArg(command)}`,
{ cwd: this.cwd, envs: e2bControlEnvs(), ...signalOpts(signal) },
{ cwd: this.ctx.e2b.cwd, envs: e2bControlEnvs(), ...signalOpts(signal) },
)
signal?.throwIfAborted()
const executable = result.stdout.trim()
if (executable.includes('\n') || (!posix.isAbsolute(executable) && !executable.includes('/'))) {
throw new Error(`subprocess-e2b: executable ${JSON.stringify(command)} did not resolve to one absolute path`)
}
return posix.resolve(this.cwd, executable)
return posix.resolve(this.ctx.e2b.cwd, executable)
}
/** @inheritdoc */
@@ -138,7 +130,7 @@ export class E2BSubprocessService extends SubprocessService {
}
}
spec.signal?.throwIfAborted()
const stateDir = posix.join(this.runtimeRoot, 'terminals', randomUUID())
const stateDir = posix.join(this.ctx.e2b.runtimeRoot, 'terminals', randomUUID())
const setup = Promise.withResolvers<void>()
const setupController = new AbortController()
const setupSignal = spec.signal === undefined

View File

@@ -775,10 +775,8 @@ describe('E2B subprocess terminal service', () => {
return { ctx, fiber, fake }
}
it('publishes execution-world coordinates and resolves remote executables', async () => {
it('resolves remote executables', async () => {
const { ctx, fake } = await service()
expect(ctx.subprocess.cwd).toBe('/workspace')
expect(ctx.subprocess.runtimeRoot).toBe('/workspace/.dsh-e2b')
await expect(ctx.subprocess.resolveExecutable('/bin/bash')).resolves.toBe('/bin/bash')
await expect(ctx.subprocess.resolveExecutable('node', { PATH: '/custom/bin' }, new AbortController().signal))
.resolves.toBe('/usr/bin/node')