Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions bunfig.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ minimumReleaseAge = 259200
# every one of these. Excluding them keeps the repo installable from scratch.
# Remove once the pins age past the window — they are exact, so this list only
# ever covers versions we already chose.
# @blaxel/core: the sandbox SDK ships fixes we depend on within hours, and the
# pin is exact, so the guard would only ever delay a version we already chose.
minimumReleaseAgeExcludes = [
"@blaxel/core",
"@expo/ui",
"@pierre/diffs",
"expo",
Expand Down
23 changes: 18 additions & 5 deletions docs/cloud-sandbox-mismatches.md
Original file line number Diff line number Diff line change
Expand Up @@ -247,17 +247,30 @@ space are volumes (one per sandbox, attached at creation, not forkable) and
Agent Drive; neither fits the golden-and-fork model, which is why memory is the
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
Resolved
lever.

**A fork takes its env on the fork request, and again on the boot script.**
`@blaxel/core` 0.3.19 accepts `envs` on `fork()`, which replaced the spec
update (and the restart it caused) that used to hand a fork its identity. The
values reach processes only when the sandbox runtime baked into the image is
current: on a golden built 2026-09-02 they landed in the spec and no process
saw them, PID 1 included; on one rebuilt 2026-09-03 every process did, and
fork plus get took under half a second. The `/app/start.sh` exec carries the
same env for goldens from before that rebuild, since everything the workspace
runs descends from it. A fork can only set or add variables, never drop one,
so promoting a workspace blanks its identity with empty values instead; an
empty value does override an inherited one (verified 2026-09-03: a golden's
`NODE_ENV=production` came back empty on a fork that set it to `""`).

**A fork can never have the egress proxy.** The proxy routing that injects
the org's model keys (`network.proxy.routing`) exists only on sandboxes created
with it: Blaxel's docs say enabling the proxy on a sandbox created without it
requires a new sandbox, and a fork is created without it (its `spec.network`
is null, and a source that carries routing hands its forks unresolved
`{{file(/var/run/secrets/…)}}` proxy templates, so every outbound request
fails with "Unsupported proxy syntax"). Applying routing to a fork with
`updateSandbox` is worse than useless: the platform builds a new instance from
the image, and the fork comes back without `node_modules`, the tools, or
anything else the environment carried (verified 2026-09-02 on a release
probe). So a workspace forked from an environment gets its model keys the
fails with "Unsupported proxy syntax"). Applying routing to a fork afterwards with a
spec update (the SDK's `updateSandbox`, which nothing in this codebase calls
any more) is worse than useless: the platform builds a new instance from the
image, and the fork comes back without `node_modules`, the tools, or anything
else the environment carried (verified 2026-09-02 on a release probe). So a workspace forked from an environment gets its model keys the
plain way, as `ANTHROPIC_API_KEY` / `OPENAI_API_KEY` in the environment's
variables, and host-service approves that key for Claude Code before an
unattended launch so it does not stop on the "use this custom API key?"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
},
"devDependencies": {
"@biomejs/biome": "2.4.2",
"@blaxel/core": "0.3.11",
"@blaxel/core": "0.3.19",
"@types/bun": "1.3.14",
"@types/semver": "7.7.1",
"dotenv-cli": "11.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/trpc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
"@aws-sdk/client-s3": "3.899.0",
"@aws-sdk/s3-request-presigner": "3.899.0",
"@azure/msal-node": "5.5.0",
"@blaxel/core": "0.3.11",
"@blaxel/core": "0.3.19",
"@googleapis/calendar": "16.0.0",
"@googleapis/gmail": "18.0.0",
"@linear/sdk": "68.1.1",
Expand Down
77 changes: 24 additions & 53 deletions packages/trpc/src/lib/blaxel/blaxel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* token — no relay hop, so websockets work and the sandbox can still sleep.
*/

import { SandboxInstance, settings, updateSandbox } from "@blaxel/core";
import { SandboxInstance, settings } from "@blaxel/core";
import { CLOUD_AGENT_LAUNCH_ENV_NAMES } from "@superset/shared/cloud-agent-launch";
import { SANDBOX_CREDENTIAL_PLACEHOLDER } from "@superset/shared/constants";
import { env } from "../../env";
Expand Down Expand Up @@ -81,33 +81,16 @@ async function forkSandbox(
workspaceEnv: Record<string, string>,
): Promise<SandboxInstance> {
const source = await SandboxInstance.get(sourceSandbox);
await source.fork(name);
const forked = await SandboxInstance.get(name);

const spec = structuredClone(forked.spec) as {
runtime?: { envs?: Array<{ name: string; value: string }> };
};
const inherited = spec.runtime?.envs ?? [];
const replaced = new Set<string>();
const envs = inherited.map((entry) => {
const override = workspaceEnv[entry.name];
if (override === undefined) return entry;
replaced.add(entry.name);
return { name: entry.name, value: override };
});
for (const [key, value] of Object.entries(workspaceEnv)) {
if (!replaced.has(key)) envs.push({ name: key, value });
}
if (!spec.runtime) spec.runtime = {};
spec.runtime.envs = envs;

await updateSandbox({
path: { sandboxName: name },
body: {
...(forked as never as { sandbox: object }).sandbox,
spec,
} as never,
throwOnError: true,
// The fork request carries the workspace's env, so no spec update and no
// restart follow it. The values also ride on the boot script's own exec
// (see provisionSandbox): a golden whose sandbox runtime predates fork
// envs hands its children the source's env instead, and the script is
// what everything the workspace runs descends from.
await source.fork(name, {
envs: Object.entries(workspaceEnv).map(([envName, value]) => ({
name: envName,
value,
})),
});
return await SandboxInstance.get(name);
}
Expand Down Expand Up @@ -188,10 +171,15 @@ export async function provisionSandbox(args: {
// Start host-service and return — the only thing provisioning runs inside a
// sandbox, and it is not awaited. The script needs a second or two; the
// client discovers the result by polling the health endpoint it already
// polls, so there is nothing to wait for here.
// polls, so there is nothing to wait for here. A fork gets its env on this
// exec as well as on the fork request, which covers goldens whose sandbox
// runtime predates fork envs (docs/cloud-sandbox-mismatches.md).
await sandbox.process.exec({
name: "host-service",
command: "/app/start.sh",
...(args.environment.sourceKind === "fork"
? { env: args.workspaceEnv }
: {}),
waitForCompletion: false,
} as never);

Expand Down Expand Up @@ -226,7 +214,13 @@ export async function promoteSandboxToEnvironment(args: {
}): Promise<string> {
configureBlaxel();
const source = await SandboxInstance.get(args.sourceSandbox);
await source.fork(args.goldenName);
// A fork inherits the source's env and can only set or add variables, never
// drop one, so the promoting workspace's identity is blanked on the fork
// request: every later workspace forked from this environment would
// otherwise carry the promoter's git token and launch the promoter's agent.
await source.fork(args.goldenName, {
envs: [...INHERITED_IDENTITY_ENVS].map((name) => ({ name, value: "" })),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: The promote path now blanks identity envs (including the git token) with empty-string values on the fork request instead of removing them from the spec. This is secure only if the fork server actually applies empty-string overrides to inherited values; if it ignores or skips them, the golden keeps the promoter's token and every later workspace inherits it. Confirm empty-value override semantics on a fork, and add a test that a public-repo workspace forked from the promoted golden does not see SUPERSET_SANDBOX_GIT_TOKEN from the promoter.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/trpc/src/lib/blaxel/blaxel.ts, line 222:

<comment>The promote path now blanks identity envs (including the git token) with empty-string values on the fork request instead of removing them from the spec. This is secure only if the fork server actually applies empty-string overrides to inherited values; if it ignores or skips them, the golden keeps the promoter's token and every later workspace inherits it. Confirm empty-value override semantics on a fork, and add a test that a public-repo workspace forked from the promoted golden does not see SUPERSET_SANDBOX_GIT_TOKEN from the promoter.</comment>

<file context>
@@ -226,7 +214,13 @@ export async function promoteSandboxToEnvironment(args: {
+	// request: every later workspace forked from this environment would
+	// otherwise carry the promoter's git token and launch the promoter's agent.
+	await source.fork(args.goldenName, {
+		envs: [...INHERITED_IDENTITY_ENVS].map((name) => ({ name, value: "" })),
+	});
 
</file context>

});

const golden = await SandboxInstance.get(args.goldenName);

Expand All @@ -248,29 +242,6 @@ export async function promoteSandboxToEnvironment(args: {
waitForCompletion: true,
} as never);

// Blaxel copies the source's env into the fork and env is immutable after
// creation, so the promoting workspace's credentials would otherwise ride
// into a shared environment every later workspace forks from. The git token
// is the dangerous one: provisioning only sets it when the clone needs it,
// so a public-repo workspace would inherit the promoter's instead.
const current = await SandboxInstance.get(args.goldenName);
const spec = structuredClone(current.spec) as {
runtime?: { envs?: Array<{ name: string; value: string }> };
};
if (spec.runtime?.envs) {
spec.runtime.envs = spec.runtime.envs.filter(
(entry) => !INHERITED_IDENTITY_ENVS.has(entry.name),
);
await updateSandbox({
path: { sandboxName: args.goldenName },
body: {
...(current as never as { sandbox: object }).sandbox,
spec,
} as never,
throwOnError: true,
});
}

return args.goldenName;
}

Expand Down
Loading