The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.
TypeScript agentai-chatai-studioall-in-onecoding-agentdesktop-appfluximage-generationlinuxllmlocal-ailocal-llmopen-sourceprivacyself-hostedstable-diffusionuncensoreduncensored-aivideo-generationwindows
test(agent): the bench fences every shell command off from the real home folder (C59)
purpleaf313d9cbf19
diff --git a/dev-server/__tests__/dev-bank-wie-die-app.test.ts b/dev-server/__tests__/dev-bank-wie-die-app.test.tsindex dde888f2..76c97644 100644--- a/dev-server/__tests__/dev-bank-wie-die-app.test.ts+++ b/dev-server/__tests__/dev-bank-wie-die-app.test.ts@@ -73,3 +73,41 @@ describe('the folder a dev shell command runs in', () => {same(devShellCwd('', 'mein-chat', undefined, heim), join(heim, AGENT_WORKSPACE_DIR, 'mein-chat'))})})++describe('the bench fence (C59, Zentrale 09.11.2026)', () => {+ it('off unless the bench asks for it, refused rather than unfenced where there is no sandbox', async () => {+ const { fenceShell } = await import('../bench-sandbox')+ expect(fenceShell('bash', ['-c', 'ls'], {})).toEqual({ bin: 'bash', args: ['-c', 'ls'] })+ expect(fenceShell('bash', ['-c', 'ls'], { LU_BENCH_SANDBOX: '1' }, 'linux')).toHaveProperty('refused')+ })++ it.runIf(process.platform === 'darwin')('a fenced command cannot read or list the real home folder, node still runs', async () => {+ const { fenceShell } = await import('../bench-sandbox')+ const { spawnSync } = await import('node:child_process')+ const os = await import('node:os')+ const home = os.userInfo().homedir+ const run = (cmd: string) => {+ const f = fenceShell('/bin/bash', ['-c', cmd], { LU_BENCH_SANDBOX: '1' })+ if ('refused' in f) throw new Error(f.refused)+ return spawnSync(f.bin, f.args, { encoding: 'utf8' })+ }+ const ls = run(`ls ${JSON.stringify(home + '/Desktop')}`)+ expect(ls.status).not.toBe(0)+ expect(ls.stderr).toMatch(/Operation not permitted/)+ const write = run(`echo x > ${JSON.stringify(home + '/c59-fence-probe.txt')}`)+ expect(write.status).not.toBe(0)+ expect(run(`${JSON.stringify(process.execPath)} -e "console.log(6*7)"`).stdout.trim()).toBe('42')+ })++ it('the file tools are already caged: an absolute path outside the workspace is refused', async () => {+ const heim = frischesHeim()+ const ws = arbeitsordnerIn(heim)+ const draussen = join(heim, 'Desktop', 'privat.txt')+ mkdirSync(join(heim, 'Desktop'), { recursive: true })+ writeFileSync(draussen, 'nicht für den Agenten')+ const res = await lesen({ path: draussen, workingDirectory: ws }, heim)+ expect(res.status).toBe(403)+ const rel = await lesen({ path: '../Desktop/privat.txt', workingDirectory: ws }, heim)+ expect(rel.status).toBe(403)+ })+})diff --git a/dev-server/bench-sandbox.ts b/dev-server/bench-sandbox.tsnew file mode 100644index 00000000..0b480d13--- /dev/null+++ b/dev-server/bench-sandbox.ts@@ -0,0 +1,56 @@+/**+ * The agent bench's hard fence (C59, Zentrale 09.11.2026).+ *+ * A bench run works in Bypass, and a shell command can go anywhere the user+ * can: in the first run a 27B searched the disk for a folder and named files+ * from the user's Desktop. With LU_BENCH_SANDBOX=1 (set by+ * playwright.agent-live.config.ts, not switchable off there) every shell+ * command of the dev server runs under macOS sandbox-exec: nothing under the+ * real home folder and nothing under /Volumes can be read or written, except+ * the toolchains a task needs (node, python) for reading. The workspace lives+ * outside the home folder (the bench's own HOME), so it stays writable.+ *+ * The file tools need no fence of their own here: the dev server's path jail+ * (lib/dev-fs-jail.ts) already keeps them inside the chat's workspace.+ *+ * Fails closed: asked for a sandbox where there is none, the command is+ * refused instead of run unfenced.+ */+import { existsSync } from 'fs'+import os from 'os'+import { dirname, sep } from 'path'++export const SANDBOX_EXEC = '/usr/bin/sandbox-exec'++const q = (p: string) => JSON.stringify(p)++/** Folders under the home that hold a toolchain: readable, never writable. */+export function toolchainDirs(realHome: string, execPath = process.execPath): string[] {+ const dirs = ['.nvm', '.local', '.cargo', '.rustup', '.pyenv', '.volta', '.bun'].map((d) => `${realHome}${sep}${d}`)+ // node itself, wherever it lives under the home (nvm, fnm, asdf …).+ const nodeRoot = dirname(dirname(execPath))+ if (nodeRoot.startsWith(realHome + sep)) dirs.push(nodeRoot)+ return dirs+}++export function benchSandboxProfile(realHome: string, readable: string[]): string {+ return [+ '(version 1)',+ '(allow default)',+ `(deny file-read-data file-write* (subpath ${q(realHome)}) (subpath "/Volumes"))`,+ ...(readable.length ? [`(allow file-read-data ${readable.map((d) => `(subpath ${q(d)})`).join(' ')})`] : []),+ ].join('\n')+}++export type Fenced = { bin: string; args: string[] } | { refused: string }++/** The command line for one shell command: fenced when the bench asks for it. */+export function fenceShell(bin: string, args: string[], env: NodeJS.ProcessEnv = process.env, platform = process.platform): Fenced {+ if (env.LU_BENCH_SANDBOX !== '1') return { bin, args }+ if (platform !== 'darwin' || !existsSync(SANDBOX_EXEC)) {+ return { refused: 'The bench sandbox is on, but this machine has no sandbox-exec. Nothing was run.' }+ }+ // The REAL home: the bench sets HOME to its own folder.+ const realHome = os.userInfo().homedir+ return { bin: SANDBOX_EXEC, args: ['-p', benchSandboxProfile(realHome, toolchainDirs(realHome)), bin, ...args] }+}diff --git a/dev-server/exec-routes.ts b/dev-server/exec-routes.tsindex fb7fc837..6b1b6a00 100644--- a/dev-server/exec-routes.ts+++ b/dev-server/exec-routes.ts@@ -6,6 +6,7 @@ import type { RouteMount } from './routes'import { requirePost, withJsonBody } from './http'import { bodyNumber, bodyString } from '../src/dev/http-body'import { devWorkspaceRoot } from '../src/lib/dev-fs-jail'+import { fenceShell } from './bench-sandbox'/*** The folder a dev-server shell command runs in, the same rule as@@ -61,7 +62,13 @@ export function registerExecRoutes(routes: RouteMount): void {return real ? '"' + real.trim() + '"' : 'python'} catch { return 'python' }})()- const proc = spawn(pythonBin, ['-c', code], {+ const fencedPy = fenceShell(pythonBin, ['-c', code])+ if ('refused' in fencedPy) {+ res.writeHead(200, { 'Content-Type': 'application/json' })+ res.end(JSON.stringify({ stdout: '', stderr: fencedPy.refused, exitCode: 1 }))+ return+ }+ const proc = spawn(fencedPy.bin, fencedPy.args, {cwd: tmpDir,stdio: ['ignore', 'pipe', 'pipe'],shell: false,@@ -132,7 +139,14 @@ export function registerExecRoutes(routes: RouteMount): void {let stderr = ''let killed = false- const proc = spawn(shellBin, shellArgs, {+ // The bench runs every shell command in its sandbox (bench-sandbox.ts).+ const fenced = fenceShell(shellBin, shellArgs)+ if ('refused' in fenced) {+ res.writeHead(200, { 'Content-Type': 'application/json' })+ res.end(JSON.stringify({ stdout: '', stderr: fenced.refused, exitCode: 1 }))+ return+ }+ const proc = spawn(fenced.bin, fenced.args, {cwd: devShellCwd(cwd, bodyString(body, 'chatId'), bodyString(body, 'workingDirectory')),stdio: ['ignore', 'pipe', 'pipe'],shell: false,diff --git a/playwright.agent-live.config.ts b/playwright.agent-live.config.tsindex 7eb8ba9f..ca6144c5 100644--- a/playwright.agent-live.config.ts+++ b/playwright.agent-live.config.ts@@ -52,6 +52,8 @@ export default defineConfig({timeout: 120_000,stdout: 'ignore',stderr: 'pipe',- env: { HOME: home, USERPROFILE: home },+ // LU_BENCH_SANDBOX: every shell command of a bench run is fenced off from+ // the real home folder (dev-server/bench-sandbox.ts). Not optional.+ env: { HOME: home, USERPROFILE: home, LU_BENCH_SANDBOX: '1' },},})