feat(p2): Gondolin sandbox environments
Some checks are pending
CI / build-check (push) Waiting to run
CI / test (coding-agent) (push) Waiting to run
CI / test (durable) (push) Waiting to run
CI / test (other) (push) Waiting to run
CI / mcp-conformance (push) Waiting to run

A sandbox is a new env type (`type: "gondolin"`): a long-lived Gondolin micro-VM on an SSH environment, with
listed host folders and an HTTP(S) host allowlist. The worker reaches it over SSH to the host, where p2's launcher
(plugins/envs/sandbox: native, or Docker when the host's Node/QEMU are too old) runs pi-env's daemon inside the VM,
so tools, workspace, terminals, uploads and MCP work unchanged. Names outside the allowlist are refused before
the host resolves them.

Conversations working in a sandbox cannot leave it: location tools, subagent spawn/configure, AgentLocations.move,
the terminal tool, and one-shot agents (which now inherit their caller's own location) all keep them there; only the
owner's Relocate moves a session out, after a confirmation. conversationConfinement() exposes it to plugins.

Owner-only management in the Envs sheet: sandboxes listed under their host, host test reports sandbox support,
create/edit/start/stop/restart/test, lock icons in the top bar and sidebar. Tests in test/p2/sandboxes.test.ts
(real VM cases with P2_TEST_GONDOLIN=1) and ui-sandboxes.test.ts; docs in docs/remote-envs.md.
This commit is contained in:
Mario Zechner 2026-11-05 23:35:04 +00:00
parent 6d3e342b25
commit 2a32a605a9
51 changed files with 3240 additions and 322 deletions

View file

@ -1,8 +1,25 @@
import { arr, nul, num, obj, opt, type Static, str, union } from "@earendil-works/pi-schema";
import { arr, bool, nul, num, obj, opt, type Static, str, union } from "@earendil-works/pi-schema";
import { DirectoryListingSchema, defineRegistry, literal, local, method, record, remote, serverHost } from "@p2/app/v1";
import type { EnvManager } from "./manager.ts";
import { EnvConfigSchema } from "./schema.ts";
/** Whether an SSH env can host sandboxes: natively, through Docker, or not (`detail` says why or how). */
export const SandboxSupportSchema = obj({
runtime: union([literal("native"), literal("docker"), literal("none")]),
detail: str(),
});
export type SandboxSupport = Static<typeof SandboxSupportSchema>;
/**
* A sandbox's VM: stopped, or running since `startedAt`; `current` is false while it runs an older configuration
* (changes apply when it restarts).
*/
export const SandboxStatusSchema = union([
obj({ state: literal("stopped") }),
obj({ state: literal("running"), startedAt: num(), cpus: num(), memoryMb: num(), current: bool() }),
]);
export type SandboxStatus = Static<typeof SandboxStatusSchema>;
export const EnvTestSchema = union([
obj({
ok: literal(true),
@ -14,6 +31,8 @@ export const EnvTestSchema = union([
latencyMs: num(),
watchMode: union([literal("native"), literal("polling")]),
warnings: arr(str()),
/** SSH envs: whether the host can run sandboxes. */
sandboxes: opt(SandboxSupportSchema),
}),
obj({
ok: literal(false),
@ -81,6 +100,12 @@ export const Envs = remote("p2.envs", {
uploadKey: method(obj({ name: str(), key: str({ maxLength: 16384 }) }), Key),
publicKey: method(Name, union([str(), nul()])),
listDirectory: method(obj({ env: opt(str()), path: str() }), DirectoryListingSchema),
/** A sandbox's VM state, read from its host. */
sandboxStatus: method(Name, SandboxStatusSchema),
/** Starts a sandbox's VM (with its current configuration) unless it runs. */
sandboxStart: method(Name, SandboxStatusSchema),
/** Stops a sandbox's VM; conversations working there reconnect and start it again at their next tool call. */
sandboxStop: method(Name, SandboxStatusSchema),
},
},
},