feat(sandbox): add KVM-backed agent sandboxing via microsandbox

This commit is contained in:
Chris Scott committed 2026-08-13 16:14:16 -04:00
1 parent 1d477bdee4
commit aa3fb48a62
80 files changed
+17304 -204

No files matched your search

@@ -203,6 +203,68 @@ describe('OpenCodeClient', () => {
Object.defineProperty(globalThis, 'fetch', { value: originalFetch, configurable: true, writable: true })
}
})
it('honours an explicit host override instead of OPENCODE_HOST', async () => {
const originalFetch = globalThis.fetch
Object.defineProperty(ENV.OPENCODE, 'HOST', { value: '192.168.1.10', configurable: true, writable: true })
let capturedUrl: URL | undefined
const fetchFn = async (input: URL | Request | string) => {
capturedUrl = input instanceof URL ? input : new URL(input.toString())
return new Response(JSON.stringify({}), { status: 200 })
}
Object.defineProperty(globalThis, 'fetch', { value: fetchFn, configurable: true, writable: true })
try {
const client = createOpenCodeClient('testpassword', '127.0.0.1')
await client.forward({ method: 'GET', path: '/doc' })
expect(capturedUrl?.origin).toBe('http://127.0.0.1:5551')
} finally {
Object.defineProperty(ENV.OPENCODE, 'HOST', { value: '127.0.0.1', configurable: true, writable: true })
Object.defineProperty(globalThis, 'fetch', { value: originalFetch, configurable: true, writable: true })
}
})
it('brackets an IPv6 loopback host in the request URL', async () => {
const originalFetch = globalThis.fetch
let capturedUrl: URL | undefined
const fetchFn = async (input: URL | Request | string) => {
capturedUrl = input instanceof URL ? input : new URL(input.toString())
return new Response(JSON.stringify({}), { status: 200 })
}
Object.defineProperty(globalThis, 'fetch', { value: fetchFn, configurable: true, writable: true })
try {
const client = createOpenCodeClient('testpassword', '::1')
await client.forward({ method: 'GET', path: '/doc' })
expect(capturedUrl?.origin).toBe('http://[::1]:5551')
} finally {
Object.defineProperty(globalThis, 'fetch', { value: originalFetch, configurable: true, writable: true })
}
})
it('resolves a lazy host override on every request', async () => {
const originalFetch = globalThis.fetch
const hosts: string[] = []
let currentHost = '192.168.1.10'
const fetchFn = async (input: URL | Request | string) => {
hosts.push(input instanceof URL ? input.hostname : new URL(input.toString()).hostname)
return new Response(JSON.stringify({}), { status: 200 })
}
Object.defineProperty(globalThis, 'fetch', { value: fetchFn, configurable: true, writable: true })
try {
const client = createOpenCodeClient('testpassword', () => currentHost)
await client.forward({ method: 'GET', path: '/doc' })
currentHost = '127.0.0.1'
await client.forward({ method: 'GET', path: '/doc' })
expect(hosts).toEqual(['192.168.1.10', '127.0.0.1'])
} finally {
Object.defineProperty(globalThis, 'fetch', { value: originalFetch, configurable: true, writable: true })
}
})
})
describe('forwardRaw', () => {