Skip to content

Commit 800602f

Browse files
feat: add microsandbox sandbox flow and feature flag toggle (anomalyco#1446)
* add pre-baked microsandbox image Bake openwork, openwork-server, and the pinned opencode binary into a single Docker image so micro-sandbox remote-connect smoke tests can boot quickly and be verified with curl and container health checks. * add Rust microsandbox example Add a standalone microsandbox SDK example that boots the OpenWork image, validates remote-connect endpoints, and streams sandbox logs so backend-only sandbox behavior can be exercised without Docker. * exclude Rust example build output Keep the standalone microsandbox example in git, but drop generated Cargo target artifacts so the branch only contains source, docs, and lockfile. * test * add microsandbox feature flag for sandbox creation Made-with: Cursor * refactor sandbox mode isolation Made-with: Cursor
1 parent 9bd844c commit 800602f

27 files changed

Lines changed: 7120 additions & 38 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { useLocal } from "../context/local";
2+
3+
export function useFeatureFlagsPreferences() {
4+
const { prefs, setPrefs } = useLocal();
5+
6+
const microsandboxCreateSandboxEnabled = () =>
7+
prefs.featureFlags?.microsandboxCreateSandbox === true;
8+
9+
const toggleMicrosandboxCreateSandbox = () => {
10+
setPrefs("featureFlags", "microsandboxCreateSandbox", (current) => !current);
11+
};
12+
13+
return {
14+
microsandboxCreateSandboxEnabled,
15+
toggleMicrosandboxCreateSandbox,
16+
};
17+
}

‎apps/app/src/app/app.tsx‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ import {
8888
import { createProvidersStore } from "./context/providers";
8989
import { ModelControlsProvider } from "./app-settings/model-controls-provider";
9090
import { createModelControlsStore } from "./app-settings/model-controls-store";
91+
import { useFeatureFlagsPreferences } from "./app-settings/feature-flags-preferences";
9192
import { useSessionDisplayPreferences } from "./app-settings/session-display-preferences";
9293
import {
9394
shouldRedirectMissingSessionAfterScopedLoad,
@@ -173,6 +174,7 @@ type StartupSessionSnapshot = {
173174

174175
export default function App() {
175176
const { resetSessionDisplayPreferences } = useSessionDisplayPreferences();
177+
const { microsandboxCreateSandboxEnabled } = useFeatureFlagsPreferences();
176178
const envOpenworkWorkspaceId =
177179
typeof import.meta.env?.VITE_OPENWORK_WORKSPACE_ID === "string"
178180
? import.meta.env.VITE_OPENWORK_WORKSPACE_ID.trim() || null
@@ -861,6 +863,7 @@ export default function App() {
861863
developerMode,
862864
pendingInitialSessionSelection,
863865
setPendingInitialSessionSelection,
866+
useMicrosandboxCreateSandbox: microsandboxCreateSandboxEnabled,
864867
});
865868

866869
createEffect(() => {

‎apps/app/src/app/bundles/skill-destination-modal.tsx‎

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { For, Show, createEffect, createMemo, createSignal } from "solid-js";
33
import { CheckCircle2, Folder, FolderPlus, Globe, Loader2, Sparkles, X } from "lucide-solid";
44
import type { WorkspaceInfo } from "../lib/tauri";
55
import { t, currentLocale } from "../../i18n";
6+
import { isSandboxWorkspace } from "../utils";
67

78
import Button from "../components/button";
89

@@ -49,12 +50,7 @@ export default function SkillDestinationModal(props: {
4950
};
5051

5152
const workspaceBadge = (workspace: WorkspaceInfo) => {
52-
if (
53-
workspace.workspaceType === "remote" &&
54-
(workspace.sandboxBackend === "docker" ||
55-
Boolean(workspace.sandboxRunId?.trim()) ||
56-
Boolean(workspace.sandboxContainerName?.trim()))
57-
) {
53+
if (isSandboxWorkspace(workspace)) {
5854
return translate("share_skill_destination.sandbox_badge");
5955
}
6056
if (workspace.workspaceType === "remote") {
@@ -78,12 +74,6 @@ export default function SkillDestinationModal(props: {
7874
void props.onSubmitWorkspace(workspaceId);
7975
};
8076

81-
const isSandboxWorkspace = (workspace: WorkspaceInfo) =>
82-
workspace.workspaceType === "remote" &&
83-
(workspace.sandboxBackend === "docker" ||
84-
Boolean(workspace.sandboxRunId?.trim()) ||
85-
Boolean(workspace.sandboxContainerName?.trim()));
86-
8777
const workspaceCircleClass = (workspace: WorkspaceInfo, selected: boolean) => {
8878
if (selected) {
8979
return "bg-indigo-7/15 text-indigo-11 border border-indigo-7/30";

‎apps/app/src/app/bundles/store.ts‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import type {
99
} from "../types";
1010
import { normalizeOpenworkServerUrl, parseOpenworkWorkspaceIdFromUrl } from "../lib/openwork-server";
1111
import { t } from "../../i18n";
12-
import { isTauriRuntime, safeStringify, addOpencodeCacheHint } from "../utils";
12+
import { isSandboxWorkspace, isTauriRuntime, safeStringify, addOpencodeCacheHint } from "../utils";
1313
import type { WorkspaceStore } from "../context/workspace";
1414
import type { StartupPreference } from "../types";
1515
import type { OpenworkServerStore } from "../connections/openwork-server-store";
@@ -662,9 +662,7 @@ export function createBundlesStore(options: {
662662
t("app.worker_fallback");
663663
const badge =
664664
workspace.workspaceType === "remote"
665-
? workspace.sandboxBackend === "docker" ||
666-
Boolean(workspace.sandboxRunId?.trim()) ||
667-
Boolean(workspace.sandboxContainerName?.trim())
665+
? isSandboxWorkspace(workspace)
668666
? t("workspace.sandbox_badge")
669667
: t("workspace.remote_badge")
670668
: t("workspace.local_badge");

‎apps/app/src/app/components/session/workspace-session-list.tsx‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import type {
2323
import {
2424
formatRelativeTime,
2525
getWorkspaceTaskLoadErrorDisplay,
26+
isSandboxWorkspace,
2627
isWindowsPlatform,
2728
} from "../../utils";
2829
import { t } from "../../../i18n";
@@ -165,9 +166,7 @@ const workspaceLabel = (workspace: WorkspaceInfo) =>
165166

166167
const workspaceKindLabel = (workspace: WorkspaceInfo) =>
167168
workspace.workspaceType === "remote"
168-
? workspace.sandboxBackend === "docker" ||
169-
Boolean(workspace.sandboxRunId?.trim()) ||
170-
Boolean(workspace.sandboxContainerName?.trim())
169+
? isSandboxWorkspace(workspace)
171170
? t("workspace.sandbox_badge")
172171
: t("workspace.remote_badge")
173172
: t("workspace.local_badge");

‎apps/app/src/app/context/local.tsx‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ type LocalPreferences = {
1414
showThinking: boolean;
1515
modelVariant: string | null;
1616
defaultModel: ModelRef | null;
17+
featureFlags: {
18+
microsandboxCreateSandbox: boolean;
19+
};
1720
};
1821

1922
type LocalContextValue = {
@@ -41,6 +44,9 @@ export function LocalProvider(props: ParentProps) {
4144
showThinking: false,
4245
modelVariant: null,
4346
defaultModel: null,
47+
featureFlags: {
48+
microsandboxCreateSandbox: false,
49+
},
4450
}),
4551
);
4652

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
export type SandboxBackendType = "docker" | "microsandbox";
2+
3+
export type SandboxCreateModeConfig = {
4+
backend: SandboxBackendType;
5+
sandboxImageRef: string | null;
6+
runtimeReadyLabel: string;
7+
runtimeCheckingStage: string;
8+
};
9+
10+
export const MICRO_SANDBOX_IMAGE_REF = "openwork-microsandbox:dev";
11+
12+
export function resolveSandboxCreateMode(useMicrosandbox: boolean): SandboxCreateModeConfig {
13+
if (useMicrosandbox) {
14+
return {
15+
backend: "microsandbox",
16+
sandboxImageRef: MICRO_SANDBOX_IMAGE_REF,
17+
runtimeReadyLabel: "Microsandbox runtime ready",
18+
runtimeCheckingStage: "Checking sandbox runtime...",
19+
};
20+
}
21+
22+
return {
23+
backend: "docker",
24+
sandboxImageRef: null,
25+
runtimeReadyLabel: "Docker ready",
26+
runtimeCheckingStage: "Checking Docker...",
27+
};
28+
}

‎apps/app/src/app/context/workspace.ts‎

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ import { t, currentLocale } from "../../i18n";
7373
import { filterProviderList, mapConfigProvidersToList } from "../utils/providers";
7474
import { buildDefaultWorkspaceBlueprint, normalizeWorkspaceOpenworkConfig } from "../lib/workspace-blueprints";
7575
import type { OpenworkServerStore } from "../connections/openwork-server-store";
76+
import { resolveSandboxCreateMode, type SandboxBackendType } from "./sandbox-create-mode";
7677

7778
export type WorkspaceStore = ReturnType<typeof createWorkspaceStore>;
7879

@@ -172,6 +173,7 @@ export function createWorkspaceStore(options: {
172173
developerMode: () => boolean;
173174
pendingInitialSessionSelection?: () => { workspaceId: string; title: string | null; readyAt: number } | null;
174175
setPendingInitialSessionSelection?: (input: { workspaceId: string; title: string | null; readyAt: number } | null) => void;
176+
useMicrosandboxCreateSandbox?: () => boolean;
175177
}) {
176178

177179
const wsDebugEnabled = () => options.developerMode();
@@ -2286,6 +2288,7 @@ export function createWorkspaceStore(options: {
22862288

22872289
const runId = makeRunId();
22882290
const startedAt = Date.now();
2291+
const sandboxMode = resolveSandboxCreateMode(options.useMicrosandboxCreateSandbox?.() === true);
22892292
setSandboxCreatePhase("preflight");
22902293
setSandboxPreflightBusy(true);
22912294
options.setError(null);
@@ -2297,11 +2300,11 @@ export function createWorkspaceStore(options: {
22972300
setSandboxCreateProgress({
22982301
runId,
22992302
startedAt,
2300-
stage: "Checking Docker...",
2303+
stage: sandboxMode.runtimeCheckingStage,
23012304
error: null,
23022305
logs: [],
23032306
steps: [
2304-
{ key: "docker", label: "Docker ready", status: "active", detail: null },
2307+
{ key: "docker", label: sandboxMode.runtimeReadyLabel, status: "active", detail: null },
23052308
{ key: "workspace", label: "Prepare worker", status: "pending", detail: null },
23062309
{ key: "sandbox", label: "Start sandbox services", status: "pending", detail: null },
23072310
{ key: "health", label: "Wait for OpenWork", status: "pending", detail: null },
@@ -2471,7 +2474,8 @@ export function createWorkspaceStore(options: {
24712474

24722475
const host = await orchestratorStartDetached({
24732476
workspacePath: resolvedFolder,
2474-
sandboxBackend: "docker",
2477+
sandboxBackend: sandboxMode.backend,
2478+
sandboxImageRef: sandboxMode.sandboxImageRef,
24752479
runId,
24762480
});
24772481
setSandboxStep("sandbox", { status: "done", detail: host.sandboxContainerName ?? null });
@@ -2487,7 +2491,7 @@ export function createWorkspaceStore(options: {
24872491
openworkHostToken: host.hostToken,
24882492
directory: resolvedFolder,
24892493
displayName: name,
2490-
sandboxBackend: host.sandboxBackend ?? "docker",
2494+
sandboxBackend: host.sandboxBackend ?? sandboxMode.backend,
24912495
sandboxRunId: host.sandboxRunId ?? runId,
24922496
sandboxContainerName: host.sandboxContainerName ?? null,
24932497
manageBusy: false,
@@ -2540,7 +2544,7 @@ export function createWorkspaceStore(options: {
25402544
closeModal?: boolean;
25412545

25422546
// Sandbox lifecycle metadata (desktop-managed)
2543-
sandboxBackend?: "docker" | null;
2547+
sandboxBackend?: SandboxBackendType | null;
25442548
sandboxRunId?: string | null;
25452549
sandboxContainerName?: string | null;
25462550
}) {
@@ -2611,7 +2615,7 @@ export function createWorkspaceStore(options: {
26112615
openworkWorkspace = resolved.workspace;
26122616
resolvedHostUrl = resolved.hostUrl;
26132617
resolvedAuth = resolved.auth;
2614-
} else if (input.sandboxBackend === "docker") {
2618+
} else if (input.sandboxBackend === "docker" || input.sandboxBackend === "microsandbox") {
26152619
resolvedHostUrl = hostUrl;
26162620
resolvedBaseUrl = `${hostUrl.replace(/\/+$/, "")}/opencode`;
26172621
resolvedDirectory = directory || resolvedDirectory;
@@ -3011,7 +3015,9 @@ export function createWorkspaceStore(options: {
30113015
}
30123016

30133017
const isSandboxWorkspace =
3014-
workspace.sandboxBackend === "docker" || Boolean(workspace.sandboxContainerName?.trim());
3018+
workspace.sandboxBackend === "docker" ||
3019+
workspace.sandboxBackend === "microsandbox" ||
3020+
Boolean(workspace.sandboxContainerName?.trim());
30153021

30163022
if (!isSandboxWorkspace) {
30173023
return Boolean(await reconnect());

‎apps/app/src/app/lib/tauri.ts‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ export type WorkspaceInfo = {
124124
openworkWorkspaceName?: string | null;
125125

126126
// Sandbox lifecycle metadata (desktop-managed)
127-
sandboxBackend?: "docker" | null;
127+
sandboxBackend?: "docker" | "microsandbox" | null;
128128
sandboxRunId?: string | null;
129129
sandboxContainerName?: string | null;
130130
};
@@ -210,7 +210,7 @@ export async function workspaceCreateRemote(input: {
210210
openworkWorkspaceName?: string | null;
211211

212212
// Sandbox lifecycle metadata (desktop-managed)
213-
sandboxBackend?: "docker" | null;
213+
sandboxBackend?: "docker" | "microsandbox" | null;
214214
sandboxRunId?: string | null;
215215
sandboxContainerName?: string | null;
216216
}): Promise<WorkspaceList> {
@@ -245,7 +245,7 @@ export async function workspaceUpdateRemote(input: {
245245
openworkWorkspaceName?: string | null;
246246

247247
// Sandbox lifecycle metadata (desktop-managed)
248-
sandboxBackend?: "docker" | null;
248+
sandboxBackend?: "docker" | "microsandbox" | null;
249249
sandboxRunId?: string | null;
250250
sandboxContainerName?: string | null;
251251
}): Promise<WorkspaceList> {
@@ -441,21 +441,23 @@ export type OrchestratorDetachedHost = {
441441
ownerToken?: string | null;
442442
hostToken: string;
443443
port: number;
444-
sandboxBackend?: "docker" | null;
444+
sandboxBackend?: "docker" | "microsandbox" | null;
445445
sandboxRunId?: string | null;
446446
sandboxContainerName?: string | null;
447447
};
448448

449449
export async function orchestratorStartDetached(input: {
450450
workspacePath: string;
451-
sandboxBackend?: "none" | "docker" | null;
451+
sandboxBackend?: "none" | "docker" | "microsandbox" | null;
452+
sandboxImageRef?: string | null;
452453
runId?: string | null;
453454
openworkToken?: string | null;
454455
openworkHostToken?: string | null;
455456
}): Promise<OrchestratorDetachedHost> {
456457
return invoke<OrchestratorDetachedHost>("orchestrator_start_detached", {
457458
workspacePath: input.workspacePath,
458459
sandboxBackend: input.sandboxBackend ?? null,
460+
sandboxImageRef: input.sandboxImageRef ?? null,
459461
runId: input.runId ?? null,
460462
openworkToken: input.openworkToken ?? null,
461463
openworkHostToken: input.openworkHostToken ?? null,

‎apps/app/src/app/pages/settings.tsx‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import WebUnavailableSurface from "../components/web-unavailable-surface";
2323
import DenSettingsPanel from "../components/den-settings-panel";
2424
import TextInput from "../components/text-input";
2525
import { useModelControls } from "../app-settings/model-controls-provider";
26+
import { useFeatureFlagsPreferences } from "../app-settings/feature-flags-preferences";
2627
import { useSessionDisplayPreferences } from "../app-settings/session-display-preferences";
2728
import { usePlatform } from "../context/platform";
2829
import ConfigView from "./config";
@@ -226,6 +227,8 @@ const BUG_REPORT_URL =
226227

227228
export default function SettingsView(props: SettingsViewProps) {
228229
const modelControls = useModelControls();
230+
const { microsandboxCreateSandboxEnabled, toggleMicrosandboxCreateSandbox } =
231+
useFeatureFlagsPreferences();
229232
const { showThinking, toggleShowThinking } = useSessionDisplayPreferences();
230233
const platform = usePlatform();
231234
const webDeployment = createMemo(() => getOpenWorkDeployment() === "web");
@@ -2006,6 +2009,33 @@ export default function SettingsView(props: SettingsViewProps) {
20062009
</div>
20072010
</div>
20082011

2012+
<div class={`${settingsPanelClass} space-y-3`}>
2013+
<div>
2014+
<div class="text-sm font-medium text-gray-12">Feature flags</div>
2015+
<div class="text-xs text-gray-9">
2016+
Experimental controls for sandbox and workspace behaviors.
2017+
</div>
2018+
</div>
2019+
2020+
<div class="flex items-center justify-between bg-gray-1 p-3 rounded-xl border border-gray-6 gap-3">
2021+
<div class="min-w-0">
2022+
<div class="text-sm text-gray-12">Create Sandbox uses microsandbox image</div>
2023+
<div class="text-xs text-gray-7">
2024+
When enabled, Create Sandbox launches the detached worker with the microsandbox
2025+
image flow instead of the default Docker image flow.
2026+
</div>
2027+
</div>
2028+
<Button
2029+
variant="outline"
2030+
class="text-xs h-8 py-0 px-3 shrink-0"
2031+
onClick={toggleMicrosandboxCreateSandbox}
2032+
disabled={props.busy || !isTauriRuntime()}
2033+
>
2034+
{microsandboxCreateSandboxEnabled() ? "On" : "Off"}
2035+
</Button>
2036+
</div>
2037+
</div>
2038+
20092039
<div class={`${settingsPanelClass} space-y-3`}>
20102040
<div class="text-sm font-medium text-gray-12">{t("settings.developer_mode_title")}</div>
20112041
<div class="text-xs text-gray-9">

0 commit comments

Comments
 (0)