import { describe, expect, it } from 'vitest'; import type { SpawnerConfig } from './config.ts'; import { containerSpec } from './sandbox.ts'; const config: SpawnerConfig = { dockerSocket: '/docker.sock', listenSocket: '/spawner.sock', image: 'registry/homepage-sandbox@sha256:abc', contentDir: '/srv/content', statusDir: '/srv/status', maxSandboxes: 16, allowNonGvisor: false, }; describe('containerSpec', () => { const spec = containerSpec(config, 'session123', 1_800_000_000, { cols: 100, rows: 30 }); const host = spec.HostConfig; it('isolates the sandbox', () => { expect(host.Privileged).toBe(false); expect(host.ReadonlyRootfs).toBe(true); expect(host.NetworkMode).toBe('none'); expect(spec.NetworkDisabled).toBe(true); expect(host.CapDrop).toEqual(['ALL']); expect(host.SecurityOpt).toContain('no-new-privileges'); expect(spec.User).toBe('agent'); }); it('limits resources', () => { expect(host.Memory).toBe(80 * 1024 * 1024); expect(host.MemorySwap).toBe(host.Memory); expect(host.NanoCpus).toBe(500_000_000); expect(host.PidsLimit).toBe(50); expect(host.LogConfig.Type).toBe('none'); }); it('mounts host paths read only', () => { expect(host.Binds).toEqual(['/srv/content:/home/agent:ro', '/srv/status:/var/status:ro']); expect(Object.values(host.Tmpfs).every((options) => options.includes('noexec'))).toBe(true); }); it('starts the terminal at the size of the browser', () => { expect(host.ConsoleSize).toEqual([30, 100]); }); it('passes only the session id and expiry into the container', () => { expect(spec.Env).toEqual(['SESSION_ID=session123', 'SESSION_EXPIRES_AT=1800000000', 'TERM=xterm-256color']); }); });