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,11 +1,22 @@
import { pluginFile } from "@earendil-works/chord/plugins";
import { contribute, defineFacet } from "@p2/app/v1";
import { HarnessEnvironments, workerOf } from "@p2/app/v1/worker";
import { loadEnvs } from "./config.ts";
import { isSandbox, loadEnvs } from "./config.ts";
import { remoteSession } from "./remote-env.ts";
import { EnvStore } from "./store.ts";
export default defineFacet((host) => {
contribute(host, "p2.worker-envs", (self) => {
const worker = workerOf(self);
const launcher = pluginFile("sandbox");
const store = self.open(
async () => {
const opened = new EnvStore(worker().init.dataDir);
await opened.observer.start();
return opened;
},
(opened) => opened.observer.close(),
);
self.contribute(HarnessEnvironments, {
remote: {
open: async (env) => {
@ -14,13 +25,19 @@ export default defineFacet((host) => {
const config = Object.hasOwn(configs, env) ? configs[env] : undefined;
if (!config) throw new Error(`Environment "${env}" is not configured; refusing local execution`);
// One connection for every conversation working on this environment, at its directories.
const remote = remoteSession(dataDir, env, config, "/");
const remote = remoteSession(dataDir, env, config, "/", { launcher });
return { at: remote.at, close: () => remote.connection.close() };
},
host: async (env) => {
describe: async (env) => {
const configs = await loadEnvs(worker().init.dataDir);
return Object.hasOwn(configs, env) ? configs[env]?.host : undefined;
const config = Object.hasOwn(configs, env) ? configs[env] : undefined;
if (config?.type === "ssh") return `the remote environment "${env}" (SSH host ${config.host})`;
if (config?.type === "gondolin")
return `the sandbox "${env}" (a VM on the environment "${config.host}"; you cannot leave it, and only its own folders and allowed hosts are reachable)`;
return undefined;
},
// The observed envs.json: a sandbox stays one while its configuration is valid (the last valid state).
sandbox: (env) => isSandbox(store.value.snapshot.configs, env),
},
});
});