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

@@ -1,6 +1,6 @@
# POC overlay: keep the advanced headless agent and model-facing tools, but
# place its filesystem and process substrate in one short-lived E2B sandbox;
# the generic Bash, PTY, LSP, and Code Runtime consumers compose above them.
# the generic Bash, PTY, and LSP consumers compose above them.
- id: base
name: '@cordisjs/plugin-include'
config:
@@ -12,9 +12,6 @@
- id: fs-local
name: '@deepseek-ai/dsh-fs-local'
disabled: true
- id: code-runtime
name: '@deepseek-ai/dsh-code-runtime-worker'
disabled: true
- insert:
- id: e2b
name: '@deepseek-ai/dsh-e2b'
@@ -25,8 +22,6 @@
name: '@deepseek-ai/dsh-subprocess-e2b'
- id: fs-e2b
name: '@deepseek-ai/dsh-fs-e2b'
- id: code-runtime-subprocess
name: '@deepseek-ai/dsh-code-runtime-subprocess'
- id: sandbox-policy
name: '@deepseek-ai/dsh-sandbox-policy'
config:

View File

@@ -3,7 +3,6 @@ import { resolve } from 'node:path'
import { boot } from '@deepseek-ai/dsh-app-boot'
import type { Agent } from '@deepseek-ai/dsh-agent'
import { Session, SessionId } from '@deepseek-ai/dsh-session'
import type {} from '@deepseek-ai/dsh-code-runtime-subprocess'
import type {} from '@deepseek-ai/dsh-fs-e2b'
import type {} from '@deepseek-ai/dsh-bash-local'
import type {} from '@deepseek-ai/dsh-lsp-local'
@@ -175,52 +174,6 @@ try {
const terminalTreeCleanup = stubbornProbe.stdout === 'gone'
if (!terminalTreeCleanup) throw new Error(`E2B PTY left process ${stubbornPid} alive after close`)
const code = await ctx.codeRuntime.run({
program: `
console.log('remote-log 你好', 42)
const doubled: number = await bridge.double({ value: 21 })
let typed = false
try {
await bridge.fail({ reason: 'expected' })
} catch (error) {
typed = error instanceof BridgeError && (error as { member: string }).member === 'fail'
}
return { doubled, typed }
`,
bindings: [{
global: 'bridge',
errorClass: { name: 'BridgeError', memberNameProperty: 'member' },
functions: {
double: async (args) => {
const value = (args as { value: number }).value
return value * 2
},
fail: async () => { throw new Error('binding rejected') },
},
}],
})
const descendantPipe = await ctx.codeRuntime.run({
program: `
const childProcess = await import('node:child_process')
const child = childProcess.spawn(
process.execPath,
['-e', 'setInterval(() => {}, 1000)', 'dsh-code-runtime-descendant'],
{ stdio: ['ignore', 'inherit', 'inherit'] },
)
return child.pid > 0
`,
bindings: [],
})
const descendantProcesses = await sandbox.commands.list()
const descendantCleanup = !descendantProcesses.some(processInfo =>
JSON.stringify([processInfo.cmd, processInfo.args]).includes('dsh-code-runtime-descendant'),
)
if (!descendantCleanup) throw new Error('E2B Code Runtime left a pipe-holding descendant alive')
const remoteProcesses = await (await ctx.e2b.getSandbox()).commands.list()
const lingeringCodeRunners = remoteProcesses.filter(processInfo =>
JSON.stringify([processInfo.cmd, processInfo.args]).includes('code-runtime-runner.mjs'),
)
process.stdout.write(`${JSON.stringify({
sandboxId: (await ctx.e2b.getSandbox()).sandboxId,
bashRead: bashRead.stdout.text,
@@ -237,10 +190,6 @@ try {
treeCleanup: terminalTreeCleanup,
scrollback: terminalScrollback.text,
},
code,
descendantPipe,
descendantCleanup,
lingeringCodeRunners: lingeringCodeRunners.length,
})}\n`)
} finally {
if (terminalId !== undefined) await ctx.pty.kill(owner, terminalId, 'fixture cleanup').catch(() => false)

View File

@@ -52,12 +52,3 @@
.ts: typescript
shutdownTimeoutMs: 1000
killGraceMs: 500
- id: code-runtime-subprocess
name: '@deepseek-ai/dsh-code-runtime-subprocess'
config:
computeMs: 500
maxWallMs: 15000
maxOutputBytes: 4096
maxOldGenerationSizeMb: 128
killGraceMs: 500