feat(runner): replace server-side bash sandbox with remote runner (#530)

* feat(runner): replace server-side bash sandbox with remote runner

* fix(runner): address review findings for output bounds, key rotation, defaults, and generated uploads

* chore(docker): remove sandbox privileges and env vars from remaining compose files

* feat(cli): add runner start with bundled SRT sandboxing (#535)

* refactor(agent): expose runner bash without skill gating

* feat(cli): add runner start with optional SRT sandboxing

* refactor(cli): remove runner Python dependency

* feat(cli): bundle SRT and use platform-native runner shells

* refactor(cli): delegate runner processes to Execa

* chore(cli): upgrade @anthropic-ai/sandbox-runtime to 0.0.83

* feat(cli): discover Bash for Windows runners

Use Pi-style Bash discovery and launch behavior, exercise the packaged CLI shell, and wait for pending ZIP metadata reads before closing cancelled downloads.

* fix(runner): enforce ownership and safe reconnects

Gate dispatch on reconciliation, retain cancellations across disconnects, and stop replaced clients. Guard the single-server runner topology with a database lease. Restage missing generated inputs, report signal exits, and bound generated-file cleanup.

* feat(webui): add Korean translations for agent runners

* feat(cli): add runner event logging and --verbose flag (#536)

* feat(cli): add runner event logging and --verbose flag

* fix(cli): log runner capacity rejections accurately and use monotonic duration
This commit is contained in:
Yiling-J
2026-11-18 15:58:57 +08:00
committed by GitHub
parent eea844320d
commit 4ac274cdd4
121 changed files with 11600 additions and 5503 deletions
+4
View File
@@ -6,6 +6,7 @@ import { parseArgs } from 'node:util'
import { fileURLToPath } from 'node:url'
import { version } from '../package.json'
import { version as cliVersion } from '../apps/cli/package.json'
import { srtBundlePlugin } from './srt-bundle'
export const cliTargets = {
'darwin-arm64': 'bun-darwin-arm64',
@@ -80,6 +81,7 @@ export async function assembleCliRelease(outdir: string, targets = cliTargetName
export async function buildCliRelease(outdir: string, targets = cliTargetNames) {
validateCliVersion(version)
if (cliVersion !== version) throw new Error('Root and CLI package versions must match')
const notices = await readFile(join(repoRoot, 'apps/cli/THIRD-PARTY-NOTICES.txt'), 'utf8')
await mkdir(outdir, { recursive: true })
const staging = await mkdtemp(join(outdir, '.build-'))
try {
@@ -90,6 +92,8 @@ export async function buildCliRelease(outdir: string, targets = cliTargetNames)
entrypoints: [join(repoRoot, 'apps/cli/src/index.ts')],
target: 'bun',
minify: true,
banner: '/*\n' + notices + '*/',
plugins: [srtBundlePlugin(...target.split('-'))],
compile: {
target: cliTargets[target],
outfile: binary,
+4
View File
@@ -2,6 +2,7 @@ import tailwindPlugin from 'bun-plugin-tailwind'
import { existsSync, readFileSync, readdirSync } from 'node:fs'
import { cp, mkdir, readdir, rm, writeFile } from 'node:fs/promises'
import path from 'node:path'
import { srtBundlePlugin } from './srt-bundle'
console.log('\n🚀 Starting NPM packaging build process for all applications...\n')
@@ -520,7 +521,10 @@ async function buildCliPackage() {
target: 'node',
outdir: binOutDir,
minify: true,
banner:
'/*\n' + readFileSync(path.join(rootDir, 'apps/cli/THIRD-PARTY-NOTICES.txt'), 'utf8') + '*/',
naming: 'shumai-cli.js',
plugins: [srtBundlePlugin()],
external: [],
define: {
'process.env.NODE_ENV': JSON.stringify('production'),
+36
View File
@@ -0,0 +1,36 @@
import { readFile } from 'node:fs/promises'
import { createRequire } from 'node:module'
import path from 'node:path'
/** Keep SRT's native helpers available in both standalone binaries and the Node bundle. */
export function srtBundlePlugin(platform?: string, arch?: string): Bun.BunPlugin {
return {
name: 'srt-vendor',
setup(build) {
build.onLoad({ filter: /[/\\]runner[/\\]srt-vendor\.ts$/ }, async () => {
const packageJson = createRequire(
new URL('../apps/cli/package.json', import.meta.url),
).resolve('@anthropic-ai/sandbox-runtime/package.json')
const names = ['java-proxy-agent/srt-proxy-agent.jar']
for (const cpu of arch ? [arch] : ['x64', 'arm64']) {
if (!platform || platform === 'linux') names.push(`seccomp/${cpu}/apply-seccomp`)
if (!platform || platform === 'windows') names.push(`srt-win/${cpu}/srt-win.exe`)
}
const assets = Object.fromEntries(
await Promise.all(
names.map(async (name) => [
name,
(await readFile(path.join(path.dirname(packageJson), 'vendor', name))).toString(
'base64',
),
]),
),
)
return {
contents: `export const bundledSrtVendor = ${JSON.stringify(assets)}`,
loader: 'js',
}
})
},
}
}
+109 -5
View File
@@ -2,10 +2,11 @@ import assert from 'node:assert/strict'
import { execFile } from 'node:child_process'
import { mkdir, mkdtemp, readFile, rm, writeFile } from 'node:fs/promises'
import { tmpdir } from 'node:os'
import { join, resolve } from 'node:path'
import { basename, join, resolve } from 'node:path'
import { promisify, parseArgs } from 'node:util'
import { randomBytes } from 'node:crypto'
import { version } from '../package.json'
import { runnerToServerMessageSchema } from '../packages/dtos/src/runner'
import { archiveName, packCliBinary, parseCliTarget, sha256 } from './build-cli'
const execFileAsync = promisify(execFile)
@@ -14,8 +15,105 @@ function assertRecord(value: unknown): asserts value is Record<string, unknown>
assert.ok(value && typeof value === 'object' && !Array.isArray(value))
}
async function testRunnerShell(binary: string, cwd: string, env: NodeJS.ProcessEnv, srt?: string) {
const key = 'fixture-runner-key'
const executionId = srt ? 'srt-shell-quotes' : 'shell-quotes'
let output = ''
let completed = false
let fixtureFailure: unknown
await writeFile(join(cwd, 'runner input.txt'), 'input with spaces\n')
const server = Bun.serve({
hostname: '127.0.0.1',
port: 0,
fetch(request, server) {
if (new URL(request.url).pathname !== '/api/runners/ws')
return new Response(null, { status: 404 })
if (request.headers.get('authorization') !== 'Bearer ' + key)
return new Response(null, { status: 401 })
if (!server.upgrade(request)) return new Response(null, { status: 426 })
},
websocket: {
open(socket) {
socket.send(
JSON.stringify({
type: 'welcome',
runnerId: 'runner-test',
runnerName: 'Native CLI',
serverTime: Date.now(),
inFlightExecutionIds: [],
}),
)
},
message(socket, raw) {
try {
const message = runnerToServerMessageSchema.parse(JSON.parse(raw.toString()))
if (message.type === 'reconcile') {
assert.equal(message.environment.platform, process.platform)
const shell = basename(message.environment.shell).toLowerCase()
assert.equal(shell, process.platform === 'win32' ? 'bash.exe' : 'sh')
socket.send(
JSON.stringify({
type: 'exec.start',
executionId,
command:
'IFS= read -r line < "runner input.txt"\nprintf \'%s | %s\' "$line" \'$literal "quotes"\'',
timeoutSec: 15,
}),
)
} else if (message.type === 'exec.output') {
assert.equal(message.executionId, executionId)
assert.equal(message.stream, 'stdout')
output += message.data
} else if (message.type === 'exec.result') {
assert.equal(message.executionId, executionId)
assert.equal(message.exitCode, 0, JSON.stringify(message))
assert.equal(output, 'input with spaces | $literal "quotes"')
completed = true
socket.close(1008)
}
} catch (error) {
fixtureFailure ??= error
socket.close(1008)
}
},
},
})
try {
const child = Bun.spawn(
[
binary,
'runner',
'start',
'--cwd',
cwd,
'--url',
server.url.origin,
...(srt ? ['--srt', srt] : []),
],
{
env: {
...env,
...(process.platform === 'win32' || srt ? { PATH: process.env.PATH } : {}),
SHUMAI_RUNNER_KEY: key,
},
signal: AbortSignal.timeout(60_000),
stderr: 'pipe',
stdout: 'ignore',
},
)
const [exitCode, stderr] = await Promise.all([child.exited, new Response(child.stderr).text()])
if (fixtureFailure) throw fixtureFailure
assert.ok(completed, 'Runner did not complete the shell command:\n' + stderr)
assert.equal(exitCode, 1, stderr)
assert.match(stderr, /Runner shell: .+/)
assert.match(stderr, /Runner access was revoked/)
} finally {
server.stop(true)
}
}
/** Exercises the packaged installer and executable against HTTP, without a runtime on PATH. */
export async function testCliRelease(outdir: string) {
export async function testCliRelease(outdir: string, srt?: string) {
const windows = process.platform === 'win32'
const target = parseCliTarget(`${windows ? 'windows' : process.platform}-${process.arch}`)
const bytes = randomBytes(65536)
@@ -200,6 +298,10 @@ export async function testCliRelease(outdir: string) {
await install()
assert.equal((await run(['--version'])).trim(), version)
assert.match(await run(['--help']), /Command line interface/)
const workspace = join(temporary, 'runner workspace')
await mkdir(workspace)
await testRunnerShell(binary, workspace, cliEnv)
if (srt) await testRunnerShell(binary, workspace, cliEnv, srt)
const projects = JSON.parse(await run(['--json', 'project', 'ls'])) as {
data: { id: string }[]
}
@@ -273,7 +375,7 @@ export async function testCliRelease(outdir: string) {
await assert.rejects(install(), /unmanaged installation/)
assert.equal(sha256(await readFile(binary)), installedHash)
console.log(
`PASS ${target}: install, API auth, mkdir, upload/download 65536 bytes, upgrade/rollback, and failure preservation`,
`PASS ${target}: install, runner shell, API auth, mkdir, upload/download 65536 bytes, upgrade/rollback, and failure preservation`,
)
} finally {
server.stop(true)
@@ -282,6 +384,8 @@ export async function testCliRelease(outdir: string) {
}
if (import.meta.main) {
const { values } = parseArgs({ options: { out: { type: 'string', default: 'out/cli-release' } } })
await testCliRelease(resolve(values.out))
const { values } = parseArgs({
options: { out: { type: 'string', default: 'out/cli-release' }, srt: { type: 'string' } },
})
await testCliRelease(resolve(values.out), values.srt ? resolve(values.srt) : undefined)
}