Simplify boot sequence, remove terminal emblem, and introduce fastfetch script for sandbox login facts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
OverlordandClaude Bot committed 2026-10-13 16:07:41 +02:00
1 parent 7937879ace
commit 5f3ff481b4
24 files changed
+232 -240

No files matched your search

+2 -1
View File
@@ -14,7 +14,8 @@ const client = new SpawnerClient(socketPath);
async function run(): Promise<void>
{
const sessionId = randomBytes(12).toString('base64url');
const containerId = await client.spawn(sessionId, Math.floor(Date.now() / 1000) + 20 * 60);
const size = { cols: process.stdout.columns ?? 80, rows: process.stdout.rows ?? 24 };
const containerId = await client.spawn(sessionId, Math.floor(Date.now() / 1000) + 20 * 60, size);
const stream = await client.attach(containerId);
const resize = () => client.resize(containerId, process.stdout.columns, process.stdout.rows).catch(() => {});
+7 -3
View File
@@ -13,7 +13,7 @@ const config: SpawnerConfig = {
};
describe('containerSpec', () => {
const spec = containerSpec(config, 'session123', 1_800_000_000);
const spec = containerSpec(config, 'session123', 1_800_000_000, { cols: 100, rows: 30 });
const host = spec.HostConfig;
it('isolates the sandbox', () => {
@@ -23,7 +23,7 @@ describe('containerSpec', () => {
expect(spec.NetworkDisabled).toBe(true);
expect(host.CapDrop).toEqual(['ALL']);
expect(host.SecurityOpt).toContain('no-new-privileges');
expect(spec.User).toBe('guest');
expect(spec.User).toBe('agent');
});
it('limits resources', () => {
@@ -35,10 +35,14 @@ describe('containerSpec', () => {
});
it('mounts host paths read only', () => {
expect(host.Binds).toEqual(['/srv/content:/home/guest:ro', '/srv/status:/var/status:ro']);
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']);
});
+8 -7
View File
@@ -1,5 +1,5 @@
import type { Socket } from 'node:net';
import { SANDBOX_LABEL, SESSION_LABEL, type ManagedContainer } from '@homepage/protocol';
import { SANDBOX_LABEL, SESSION_LABEL, type ManagedContainer, type TerminalSize } from '@homepage/protocol';
import type { SpawnerConfig } from './config.ts';
import { DockerClient, DockerError } from './docker.ts';
@@ -10,12 +10,12 @@ const MiB = 1024 * 1024;
* validated session id and expiry come from outside. It must stay identical
* to deploy/host/sandbox-flags.sh.
*/
export function containerSpec(config: SpawnerConfig, sessionId: string, expiresAt: number)
export function containerSpec(config: SpawnerConfig, sessionId: string, expiresAt: number, size: TerminalSize)
{
return {
Image: config.image,
User: 'guest',
Hostname: 'sandbox',
User: 'agent',
Hostname: 'security-command',
Env: [`SESSION_ID=${sessionId}`, `SESSION_EXPIRES_AT=${expiresAt}`, 'TERM=xterm-256color'],
Tty: true,
OpenStdin: true,
@@ -39,8 +39,9 @@ export function containerSpec(config: SpawnerConfig, sessionId: string, expiresA
Ulimits: [{ Name: 'nofile', Soft: 256, Hard: 256 }],
// The content is the read only home directory, so /tmp is the only writable place.
Tmpfs: { '/tmp': 'size=8m,noexec,nosuid' },
Binds: [`${config.contentDir}:/home/guest:ro`, `${config.statusDir}:/var/status:ro`],
Binds: [`${config.contentDir}:/home/agent:ro`, `${config.statusDir}:/var/status:ro`],
LogConfig: { Type: 'none', Config: {} },
ConsoleSize: [size.rows, size.cols],
AutoRemove: true,
},
};
@@ -75,7 +76,7 @@ export class SandboxManager {
}
}
async spawn(sessionId: string, expiresAt: number): Promise<string>
async spawn(sessionId: string, expiresAt: number, size: TerminalSize): Promise<string>
{
const existing = await this.list();
if (existing.length >= this.config.maxSandboxes) throw new Error('sandbox limit reached');
@@ -83,7 +84,7 @@ export class SandboxManager {
const created = await this.docker.call<{ Id: string }>(
'POST',
`/containers/create?name=sandbox-${sessionId}`,
containerSpec(this.config, sessionId, expiresAt),
containerSpec(this.config, sessionId, expiresAt, size),
);
return created.Id;
+3 -3
View File
@@ -113,7 +113,7 @@ describe('spawner server', () => {
});
it('creates a sandbox with the hardcoded spec', async () => {
const containerId = await client.spawn('session123', Math.floor(Date.now() / 1000) + 600);
const containerId = await client.spawn('session123', Math.floor(Date.now() / 1000) + 600, { cols: 80, rows: 24 });
expect(containerId).toBe('ccccccccccc2');
const create = calls.find((call) => call.path === '/containers/create');
expect(create?.body).toMatchObject({ Image: 'sandbox@sha256:abc', HostConfig: { NetworkMode: 'none' } });
@@ -121,8 +121,8 @@ describe('spawner server', () => {
it('refuses to spawn beyond the sandbox limit', async () => {
const expiresAt = Math.floor(Date.now() / 1000) + 600;
await client.spawn('session123', expiresAt);
await expect(client.spawn('session456', expiresAt)).rejects.toThrow('sandbox limit reached');
await client.spawn('session123', expiresAt, { cols: 80, rows: 24 });
await expect(client.spawn('session456', expiresAt, { cols: 80, rows: 24 })).rejects.toThrow('sandbox limit reached');
});
it('attaches before starting and bridges the stream', async () => {
+1 -1
View File
@@ -40,7 +40,7 @@ async function handle(connection: Socket, manager: SandboxManager, log: Logger):
switch (request.op)
{
case 'spawn': {
const containerId = await manager.spawn(request.sessionId, request.expiresAt);
const containerId = await manager.spawn(request.sessionId, request.expiresAt, { cols: request.cols, rows: request.rows });
log(`spawned ${containerId.slice(0, 12)} for session ${request.sessionId}`);
respond(connection, { ok: true, containerId });
break;