Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

fix(antigravity): protect staged skill roots from boxed agents

Krishna Dobhal86d6d86f9f9c
diff --git a/server/bot-box/plan.test.ts b/server/bot-box/plan.test.ts
index 856945690d..13b0f909f0 100644
--- a/server/bot-box/plan.test.ts
+++ b/server/bot-box/plan.test.ts
@@ -21,6 +21,24 @@ const turn = (mutate?: BoxMutation[]) => planBox(setup(mutate), {
// over POSIX paths, which Windows' path module would write with drive letters and backslashes.
const linuxBox = describe.skipIf(process.platform === "win32");
+describe("explicit read-only grants", () => {
+ it("overrides a writable engine profile for its staged skills", () => {
+ const home = join(process.cwd(), "box-fixture-home");
+ const dataDir = join(home, "data");
+ const profile = join(dataDir, "providers", "antigravity", "account");
+ const skills = join(profile, "omb-skills");
+ const plan = planBox({ dataDir, home, codeRoots: [], engineRoots: [], bridges: [] }, {
+ command: "antigravity", args: [], cwd: join(dataDir, "task-workspaces", "bot", "thread"),
+ env: { HOME: home, GEMINI_HOME: profile }, ro: [skills],
+ });
+ expect(visibleInBox(plan, join(skills, "hash", "SKILL.md"))).toBe("ro");
+ expect(visibleInBox(plan, join(profile, "antigravity-acp", "acp_token.json"))).toBe("rw");
+ const args = bwrapArgs(plan);
+ expect(args).toContain("--ro-bind-try");
+ expect(args.slice(args.indexOf(skills) - 1, args.indexOf(skills) + 2)).toEqual(["--ro-bind-try", skills, skills]);
+ });
+});
+
linuxBox("the box plan", () => {
it("shows the turn its own folders and the code, and nothing else of the data folder", () => {
const plan = turn();
diff --git a/server/bot-box/plan.ts b/server/bot-box/plan.ts
index aa49c6e5c7..7d8546421f 100644
--- a/server/bot-box/plan.ts
+++ b/server/bot-box/plan.ts
@@ -247,7 +247,7 @@ export function planBox(setup: BoxSetup, request: BoxRequest): BoxPlan {
// gave no bot (a configured server's program lives in the folder of the bot that added it).
if (!named.has(full) && (under(full, dataDir) || under(dataDir, full)) && !covered(full) && !inBotFolder(full)) continue;
// Code and the system are already there; a file under HOME or /tmp the command line names is put back read-only.
- if (covered(full) || readOnly.has(full)) continue;
+ if ((!named.has(full) && covered(full)) || readOnly.has(full)) continue;
if (["/usr", "/etc", "/opt", "/var/lib", ...setup.codeRoots, ...setup.engineRoots].some((base) => under(full, resolve(base)))) continue;
readOnly.add(full);
mounts.push({ kind: "ro", source: full, target: full, optional: true });
diff --git a/server/drivers/acp/client-path.test.ts b/server/drivers/acp/client-path.test.ts
index 1a56176e0f..0d2b5ae0b8 100644
--- a/server/drivers/acp/client-path.test.ts
+++ b/server/drivers/acp/client-path.test.ts
@@ -1,4 +1,4 @@
-import { mkdirSync, realpathSync, symlinkSync, writeFileSync } from "node:fs";
+import { mkdirSync, realpathSync, renameSync, symlinkSync, writeFileSync } from "node:fs";
import { join } from "node:path";
import { describe, expect, it } from "vitest";
@@ -9,9 +9,10 @@ describe("ACP client paths", () => {
it("allows turn-selected profile reads without granting writes or other profile files", async () => {
const cwd = join(DATA_DIR, "client-task");
const profile = join(DATA_DIR, "profile");
- const skill = join(profile, "omb-skills", "hash");
+ let skill = join(profile, "omb-skills", "hash");
mkdirSync(cwd, { recursive: true });
mkdirSync(join(skill, "references"), { recursive: true });
+ skill = realpathSync(skill);
const file = join(skill, "references", "guide.md");
writeFileSync(file, "reviewed");
await expect(resolveAcpClientPath(file, cwd, [skill])).resolves.toBe(realpathSync(file));
@@ -22,4 +23,32 @@ describe("ACP client paths", () => {
symlinkSync(cwd, join(skill, "escape"), process.platform === "win32" ? "junction" : "dir");
await expect(resolveAcpClientPath(join(skill, "escape", "new.md"), cwd, [skill])).rejects.toThrow("outside");
});
+
+ it.each(["root", "parent"])("rejects a staged %s replaced after staging", async (part) => {
+ const base = join(DATA_DIR, "swapped-" + part);
+ const cwd = join(base, "task");
+ const parent = join(base, "omb-skills");
+ mkdirSync(cwd, { recursive: true });
+ mkdirSync(join(parent, "hash"), { recursive: true });
+ const root = realpathSync(join(parent, "hash"));
+ const file = join(root, "secret.md");
+ writeFileSync(file, "reviewed");
+ await expect(resolveAcpClientPath(file, cwd, [root])).resolves.toBe(file);
+ const outside = join(base, "outside");
+ mkdirSync(part === "parent" ? join(outside, "hash") : outside, { recursive: true });
+ writeFileSync(join(outside, ...(part === "parent" ? ["hash", "secret.md"] : ["secret.md"])), "private");
+ const swapped = part === "parent" ? realpathSync(parent) : root;
+ renameSync(swapped, swapped + "-original");
+ symlinkSync(outside, swapped, process.platform === "win32" ? "junction" : "dir");
+ await expect(resolveAcpClientPath(file, cwd, [root])).rejects.toThrow("expected location");
+ });
+
+ it("keeps symlinked workspace resolution unchanged", async () => {
+ const real = join(DATA_DIR, "real-workspace");
+ const linked = join(DATA_DIR, "linked-workspace");
+ mkdirSync(real, { recursive: true });
+ writeFileSync(join(real, "note.md"), "workspace");
+ symlinkSync(real, linked, process.platform === "win32" ? "junction" : "dir");
+ await expect(resolveAcpClientPath(join(linked, "note.md"), linked)).resolves.toBe(realpathSync(join(real, "note.md")));
+ });
});
diff --git a/server/drivers/acp/client-path.ts b/server/drivers/acp/client-path.ts
index b5da031cdd..f1d43a1fd2 100644
--- a/server/drivers/acp/client-path.ts
+++ b/server/drivers/acp/client-path.ts
@@ -9,6 +9,14 @@ const inside = (root: string, path: string) => {
export async function resolveAcpClientPath(requestPath: unknown, cwd: string, readRoots: readonly string[] = []): Promise<string> {
if (typeof requestPath !== "string" || !isAbsolute(requestPath)) throw new Error("ACP file paths must be absolute.");
const requested = resolve(requestPath);
+ const stagedRoot = readRoots.find((allowed) => inside(resolve(allowed), requested));
+ if (stagedRoot) {
+ const expected = resolve(stagedRoot);
+ const info = await lstat(expected);
+ if (!info.isDirectory() || info.isSymbolicLink() || await realpath(expected) !== expected) {
+ throw new Error("ACP staged read root must be a real directory at its expected location.");
+ }
+ }
const root = [cwd, ...readRoots].find((allowed) => inside(resolve(allowed), requested));
if (!root) throw new Error("ACP file path is outside the session workspace.");
const workspace = await realpath(root).catch(() => resolve(root));
diff --git a/server/drivers/acp/core.ts b/server/drivers/acp/core.ts
index cf2e4c2acc..e401fcf7b3 100644
--- a/server/drivers/acp/core.ts
+++ b/server/drivers/acp/core.ts
@@ -165,7 +165,7 @@ export interface AcpSupport {
env: Record<string, string | undefined>,
config: AcpConfig,
instanceId: string,
- ): Promise<{ command: string; args?: string[]; env?: Record<string, string | undefined> }>;
+ ): Promise<{ command: string; args?: string[]; env?: Record<string, string | undefined>; ro?: readonly string[] }>;
/** Snapshot override for agents whose binary has no conventional --version. */
snapshot?(
env: Record<string, string | undefined>,
@@ -600,11 +600,11 @@ export function createAcpDriver(support: AcpSupport): ProviderDriver<AcpConfig>
for (const host of hosts) if (host.key === hostKey && host.accepts(SHARED_SESSIONS_MAX, SHARED_SESSIONS_LIFETIME, threadId, cwd)) return host;
return null;
};
- const hostFor = (threadId: string, launch: { command: string }, argv: string[], env: Record<string, string | undefined>, cwd: string,
+ const hostFor = (threadId: string, launch: { command: string; ro?: readonly string[] }, argv: string[], env: Record<string, string | undefined>, cwd: string,
hostKey: string | null): AcpHost => {
const running = sharedHost(hostKey, threadId, cwd);
if (running) return running;
- const child = spawnCli(launch.command, argv, { cwd, env, stdio: ["pipe", "pipe", "pipe"], box: { allowEnv: instanceEnvNames(input.environment, env), botThreads: hostKey !== null } }, "bot");
+ const child = spawnCli(launch.command, argv, { cwd, env, stdio: ["pipe", "pipe", "pipe"], box: { allowEnv: instanceEnvNames(input.environment, env), botThreads: hostKey !== null, ro: launch.ro } }, "bot");
const host = new AcpHost(child, hostKey, { source: SOURCE, logMessage: nativeLogMessage, unrouted: refuse });
hosts.add(host);
child.once("close", () => hosts.delete(host));
@@ -614,7 +614,7 @@ export function createAcpDriver(support: AcpSupport): ProviderDriver<AcpConfig>
const openSession = (
threadId: string,
- launch: { command: string; args?: string[] },
+ launch: { command: string; args?: string[]; ro?: readonly string[] },
argv: string[],
env: Record<string, string | undefined>,
cwd: string,
@@ -1001,7 +1001,7 @@ export function createAcpDriver(support: AcpSupport): ProviderDriver<AcpConfig>
resolvedModel !== undefined && resolvedModel !== turn.model
? { ...turn, model: resolvedModel }
: turn;
- let launch: { command: string; args?: string[]; env?: Record<string, string | undefined> };
+ let launch: { command: string; args?: string[]; env?: Record<string, string | undefined>; ro?: readonly string[] };
try {
launch = support.resolveCommand
? await support.resolveCommand(env, turnConfig, instanceId)
@@ -1028,7 +1028,7 @@ export function createAcpDriver(support: AcpSupport): ProviderDriver<AcpConfig>
? createHash("sha256").update(support.toolScopeCacheKey({ config: turnConfig, env, cwd })).digest("hex") : null;
const processContract = [launch.command, launch.args ?? [], spawnArgs,
support.sessionScopedApproval ? null : turnConfig.fullAuto === true, envFingerprint,
- support.spawnFingerprint?.(spawnEnv, turnConfig) ?? null];
+ support.spawnFingerprint?.(spawnEnv, turnConfig) ?? null, launch.ro ?? []];
const contractKey = JSON.stringify([...processContract, cwd, turn.toolScope ?? null, inheritedScopeFingerprint]);
const launchModel = support.sessionModelEnv && cliTurn.model && /^[\w.:/-]{1,200}$/u.test(cliTurn.model)
&& catalog.accountModels?.has(cliTurn.model) ? cliTurn.model : undefined;
@@ -1563,11 +1563,11 @@ export function createAcpDriver(support: AcpSupport): ProviderDriver<AcpConfig>
try {
const turn = { threadId: `memory-text-${newId()}`, text: prompt, approvalMode: "ask", cwd } as SendTurnInput;
support.applyTurnEnv?.(env, { fullAuto: false, cwd, threadId: turn.threadId, mcpServers: [] });
- const launch = support.resolveCommand ? await support.resolveCommand(env, turnConfig, instanceId) : { command: turnConfig.cli };
+ const launch: { command: string; args?: string[]; env?: Record<string, string | undefined>; ro?: readonly string[] } = support.resolveCommand ? await support.resolveCommand(env, turnConfig, instanceId) : { command: turnConfig.cli };
const spawnEnv = launch.env ?? env;
return await runAcpOneShot({
displayName: support.displayName,
- spawn: spawnCli, kill: killCliTree, box: { allowEnv: instanceEnvNames(input.environment, spawnEnv) },
+ spawn: spawnCli, kill: killCliTree, box: { allowEnv: instanceEnvNames(input.environment, spawnEnv), ro: launch.ro },
command: launch.command,
argv: [...(launch.args ?? []), ...support.spawnArgs(turnConfig, turn)],
env: spawnEnv,
diff --git a/server/drivers/antigravity-acp.ts b/server/drivers/antigravity-acp.ts
index f02e7d9011..b19fb57fb8 100644
--- a/server/drivers/antigravity-acp.ts
+++ b/server/drivers/antigravity-acp.ts
@@ -1,5 +1,5 @@
import { createHash, randomUUID } from "node:crypto";
-import { mkdir, mkdtemp, readFile, rm, stat } from "node:fs/promises";
+import { lstat, mkdir, mkdtemp, readFile, rm, stat } from "node:fs/promises";
import { request as httpRequest } from "node:http";
import { tmpdir } from "node:os";
import { delimiter, join, resolve } from "node:path";
@@ -145,6 +145,9 @@ export async function prepareAntigravityProfile(input: {
const directory = resolve(input.profileDirectory ?? antigravityProfileDirectory(input.instanceId, input.baseDir));
const acpDirectory = join(directory, "antigravity-acp");
await mkdir(acpDirectory, { recursive: true, mode: 0o700 });
+ const skillsDirectory = join(directory, "omb-skills");
+ await mkdir(skillsDirectory, { recursive: true, mode: 0o700 });
+ if (!(await lstat(skillsDirectory)).isDirectory()) throw new Error("Antigravity staging path must be a real directory.");
if (process.platform !== "win32") {
const { chmod } = await import("node:fs/promises");
await chmod(directory, 0o700);
@@ -240,7 +243,7 @@ export class AntigravityAcpClient {
this.child = spawnCli(
runtime.executablePath,
process.platform === "linux" ? ["--uid="] : [],
- { cwd, env: profile.environment, stdio: ["pipe", "pipe", "pipe"], ...(relay ? { box: { relay: relay.socketPath } } : {}) },
+ { cwd, env: profile.environment, stdio: ["pipe", "pipe", "pipe"], box: { ro: [join(profile.directory, "omb-skills")], ...(relay ? { relay: relay.socketPath } : {}) } },
"bot",
);
this.child.stdout!.setEncoding("utf8");
diff --git a/server/drivers/antigravity.test.ts b/server/drivers/antigravity.test.ts
index f9f8032edf..503b24325a 100644
--- a/server/drivers/antigravity.test.ts
+++ b/server/drivers/antigravity.test.ts
@@ -1,4 +1,4 @@
-import { chmodSync, copyFileSync, existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, realpathSync, rmSync, statSync, unlinkSync, writeFileSync } from "node:fs";
+import { chmodSync, copyFileSync, existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, realpathSync, rmSync, statSync, symlinkSync, unlinkSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { dirname, join } from "node:path";
import { fileURLToPath, pathToFileURL } from "node:url";
@@ -568,6 +568,19 @@ describe("official Antigravity runtime", () => {
expect(readdirSync(acpDirectory).filter((name) => name.endsWith(".tmp"))).toEqual([]);
});
+ it("refuses a symlinked staging root before launching a profile process", async () => {
+ const fake = fakeRuntime();
+ const runtime = await resolveAntigravityRuntime(fake.executable);
+ const profileDirectory = join(fake.directory, "profile");
+ const outside = join(fake.directory, "outside");
+ mkdirSync(profileDirectory);
+ mkdirSync(outside);
+ symlinkSync(outside, join(profileDirectory, "omb-skills"), process.platform === "win32" ? "junction" : "dir");
+ await expect(prepareAntigravityProfile({ instanceId: "linked-staging", runtime, baseEnv: {}, profileDirectory }))
+ .rejects.toThrow("Antigravity staging path must be a real directory.");
+ expect(readdirSync(outside)).toEqual([]);
+ });
+
it("keeps the existing Google sign-in when the runtime version changes", async () => {
const fake = fakeRuntime();
const runtime = await resolveAntigravityRuntime(fake.executable);
@@ -958,6 +971,8 @@ describe("Antigravity driver over shared ACP", () => {
expect(replies.get("skill-write").error.message).toContain("outside");
expect(replies.get("token-read").error.message).toContain("outside");
const dumpState = JSON.parse(readFileSync(dump, "utf8"));
+ const turnSpawn = vi.mocked(procs.spawnCli).mock.calls.find((call) => call[2].cwd === fake.directory);
+ expect(turnSpawn?.[2].box).toMatchObject({ ro: [join(antigravityProfileDirectory(instanceId), "omb-skills")] });
expect(dumpState.argv).toEqual(process.platform === "linux" ? ["--uid="] : []);
expect(dumpState.env.GEMINI_HOME).toBe(antigravityProfileDirectory(instanceId));
expect(dumpState.env.GEMINI_API_KEY).toBeUndefined();
diff --git a/server/drivers/antigravity.ts b/server/drivers/antigravity.ts
index e495a159e5..a699f69d0f 100644
--- a/server/drivers/antigravity.ts
+++ b/server/drivers/antigravity.ts
@@ -1,7 +1,7 @@
// Google Antigravity through its official ACP server: managed runtime, isolated Google profile,
// model/mode configuration and OAuth.
import type { ApprovalMode } from "../../shared/approval-mode.ts";
-import { dirname } from "node:path";
+import { dirname, join } from "node:path";
import { stageAntigravitySkills } from "./antigravity-skills.ts";
import { antigravityAccount } from "./antigravity-account.ts";
import type {
@@ -90,6 +90,7 @@ const support: AcpSupport = {
command: runtime.executablePath,
args: process.platform === "linux" ? ["--uid="] : [],
env: profile.environment,
+ ro: [join(profile.directory, "omb-skills")],
};
},