diff --git a/app/api/sandbox/create/route.ts b/app/api/sandbox/create/route.ts index ae9e101..1d1fbbf 100644 --- a/app/api/sandbox/create/route.ts +++ b/app/api/sandbox/create/route.ts @@ -2,7 +2,6 @@ import { NextResponse } from "next/server" import { execFile, spawn } from "node:child_process" import { promisify } from "node:util" import { inspectSandbox } from "@/app/lib/openshellHost" -import { repairOpenClawWorkspacePermissions, stabilizeOpenClawGatewayConfig } from "@/app/lib/sandboxPrivilegedFiles" import { commandExists, HOST_PATH, @@ -58,60 +57,6 @@ type NemoClawCreateCommand = { mode: "cli-onboard" | "legacy-setup" } -type CreateInferenceMode = "auto" | "vllm" | "nim" - -type CreateInferenceSettings = { - mode: CreateInferenceMode - model: string - hasApiKey: boolean - envSummary: string[] -} - -function parseCreateInferenceSettings(body: any): CreateInferenceSettings { - const raw = body?.createInference && typeof body.createInference === "object" ? body.createInference : {} - const requestedMode = typeof raw.mode === "string" ? raw.mode : "auto" - const mode: CreateInferenceMode = requestedMode === "vllm" || requestedMode === "nim" ? requestedMode : "auto" - const model = typeof raw.model === "string" ? raw.model.trim() : "" - const apiKey = typeof raw.apiKey === "string" ? raw.apiKey.trim() : "" - - return { - mode, - model, - hasApiKey: Boolean(apiKey), - envSummary: [], - } -} - -function applyCreateInferenceEnv(env: NodeJS.ProcessEnv, settings: CreateInferenceSettings, body: any) { - if (settings.mode === "auto") return settings - - env.NEMOCLAW_EXPERIMENTAL = "1" - settings.envSummary.push("NEMOCLAW_EXPERIMENTAL=1") - - if (settings.mode === "vllm") { - env.NEMOCLAW_PROVIDER = "vllm" - settings.envSummary.push("NEMOCLAW_PROVIDER=vllm") - } - - if (settings.mode === "nim") { - env.NEMOCLAW_PROVIDER = "nim-local" - settings.envSummary.push("NEMOCLAW_PROVIDER=nim-local") - const apiKey = typeof body?.createInference?.apiKey === "string" ? body.createInference.apiKey.trim() : "" - if (apiKey) { - env.NVIDIA_API_KEY = apiKey - env.NEMOCLAW_PROVIDER_KEY = apiKey - settings.envSummary.push("NVIDIA_API_KEY=", "NEMOCLAW_PROVIDER_KEY=") - } - } - - if (settings.model) { - env.NEMOCLAW_MODEL = settings.model - settings.envSummary.push(`NEMOCLAW_MODEL=${settings.model}`) - } - - return settings -} - function buildNemoClawCreateCommand(): NemoClawCreateCommand { if (NEMOCLAW_BIN && commandExists(NEMOCLAW_BIN)) { const args = ["onboard", "--non-interactive", "--recreate-sandbox", "--yes-i-accept-third-party-software"] @@ -386,8 +331,7 @@ export async function POST(request: Request) { const sandboxName = validateSandboxName(typeof body?.sandboxName === "string" ? body.sandboxName.trim() : "") const policy = body?.policy && typeof body.policy === "object" ? body.policy : null const enableTailscale = Boolean(body?.enableTailscale) - const createInference = parseCreateInferenceSettings(body) - console.log(`[sandbox/create] request:parsed sandbox=${sandboxName} blueprint=${blueprint} enableTailscale=${enableTailscale} inferenceMode=${createInference.mode} elapsedMs=${elapsedMs(requestStartedAt)}`) + console.log(`[sandbox/create] request:parsed sandbox=${sandboxName} blueprint=${blueprint} enableTailscale=${enableTailscale} elapsedMs=${elapsedMs(requestStartedAt)}`) if (!blueprint) { return NextResponse.json({ ok: false, error: "blueprint is required" }, { status: 400 }) @@ -409,8 +353,6 @@ export async function POST(request: Request) { env.NVIDIA_API_KEY = env.NVIDIA_API_KEY || "optional-local-mode" } - applyCreateInferenceEnv(env, createInference, body) - const result = await runCommand( createCommand.file, createCommand.mode === "legacy-setup" ? [...createCommand.args, sandboxName] : createCommand.args, @@ -427,7 +369,6 @@ export async function POST(request: Request) { blueprint, sandboxName, enableTailscale, - createInference, }, { status: 500 }) } @@ -438,16 +379,6 @@ export async function POST(request: Request) { error: "Sandbox readiness polling produced no verification result.", } const created = readiness.verified - const gatewayConfigRepair = created ? await stabilizeOpenClawGatewayConfig(sandboxName).catch((error) => ({ - sandboxName, - path: "/sandbox/.openclaw/openclaw.json", - error: error instanceof Error ? error.message : "Failed to stabilize OpenClaw gateway config", - })) : null - const workspaceRepair = created ? await repairOpenClawWorkspacePermissions(sandboxName).catch((error) => ({ - sandboxName, - path: "/sandbox/.openclaw/workspace", - error: error instanceof Error ? error.message : "Failed to repair OpenClaw workspace permissions", - })) : null const deviceApproval = created ? await approveOpenClawDeviceRequests(sandboxName) : null console.log( `[sandbox/create] request:complete sandbox=${sandboxName} created=${created} readinessAttempts=${readiness.attempts} deviceApproval=${deviceApproval?.approved ?? false} elapsedMs=${elapsedMs(requestStartedAt)}`, @@ -462,15 +393,12 @@ export async function POST(request: Request) { verification, mode: "nemoclaw-blueprint", enableTailscale, - createInference, createCommand, hostPath: HOST_PATH, readiness: { attempts: readiness.attempts, elapsedMs: readiness.elapsedMs, }, - workspaceRepair, - gatewayConfigRepair, deviceApproval, stdout: result.stdout, stderr: result.stderr, @@ -479,10 +407,6 @@ export async function POST(request: Request) { enableTailscale ? "NemoClaw blueprint workflow completed with Tailscale-enabled prerequisites. Existing healthy OpenShell gateways are reused before any new gateway start is attempted." : "NemoClaw blueprint workflow completed in local/default mode. Existing healthy OpenShell gateways are reused before any new gateway start is attempted.", - workspaceRepair && "note" in workspaceRepair ? workspaceRepair.note : false, - workspaceRepair && "error" in workspaceRepair ? `OpenClaw workspace permission repair failed: ${workspaceRepair.error}` : false, - gatewayConfigRepair && "note" in gatewayConfigRepair ? gatewayConfigRepair.note : false, - gatewayConfigRepair && "error" in gatewayConfigRepair ? `OpenClaw gateway config repair failed: ${gatewayConfigRepair.error}` : false, deviceApproval?.note, ) : "Blueprint command reported success, but the sandbox never reached a ready verification state afterward.", @@ -517,16 +441,6 @@ export async function POST(request: Request) { error: "Sandbox readiness polling produced no verification result.", } const created = readiness.verified - const gatewayConfigRepair = created ? await stabilizeOpenClawGatewayConfig(sandboxName).catch((error) => ({ - sandboxName, - path: "/sandbox/.openclaw/openclaw.json", - error: error instanceof Error ? error.message : "Failed to stabilize OpenClaw gateway config", - })) : null - const workspaceRepair = created ? await repairOpenClawWorkspacePermissions(sandboxName).catch((error) => ({ - sandboxName, - path: "/sandbox/.openclaw/workspace", - error: error instanceof Error ? error.message : "Failed to repair OpenClaw workspace permissions", - })) : null const deviceApproval = created ? await approveOpenClawDeviceRequests(sandboxName) : null const policyPrepared = Boolean(policy) console.log( @@ -553,8 +467,6 @@ export async function POST(request: Request) { attempts: readiness.attempts, elapsedMs: readiness.elapsedMs, }, - workspaceRepair, - gatewayConfigRepair, deviceApproval, policyPrepared, note: created @@ -564,10 +476,6 @@ export async function POST(request: Request) { : (policyPrepared ? "Custom sandbox created. Policy draft is prepared, but applying it live should be a follow-up action." : "Custom sandbox created."), - workspaceRepair && "note" in workspaceRepair ? workspaceRepair.note : false, - workspaceRepair && "error" in workspaceRepair ? `OpenClaw workspace permission repair failed: ${workspaceRepair.error}` : false, - gatewayConfigRepair && "note" in gatewayConfigRepair ? gatewayConfigRepair.note : false, - gatewayConfigRepair && "error" in gatewayConfigRepair ? `OpenClaw gateway config repair failed: ${gatewayConfigRepair.error}` : false, deviceApproval?.note, ) : "Create command started, but the sandbox never reached a ready verification state afterward.", diff --git a/app/api/sandbox/delete/route.ts b/app/api/sandbox/delete/route.ts index 4c26acf..e6f6837 100644 --- a/app/api/sandbox/delete/route.ts +++ b/app/api/sandbox/delete/route.ts @@ -1,10 +1,8 @@ import { NextResponse } from "next/server" import { execFile } from "node:child_process" -import { mkdir, readFile, writeFile } from "node:fs/promises" -import path from "node:path" import { promisify } from "node:util" import { resolveSandboxRef } from "@/app/lib/openshellHost" -import { OPENSHELL_BIN, hostCommandEnv } from "@/app/lib/hostCommands" +import { HOST_PATH, NEMOCLAW_BIN, NEMOCLAW_CWD, OPENSHELL_BIN } from "@/app/lib/hostCommands" const execFileAsync = promisify(execFile) @@ -56,9 +54,14 @@ async function deleteSandbox(sandboxName: string) { console.log(`[sandbox/delete] command:start sandbox=${sandboxName}`) try { const { stdout, stderr } = await execFileAsync(OPENSHELL_BIN, ["sandbox", "delete", sandboxName], { - env: hostCommandEnv({ + env: { + ...process.env, + PATH: HOST_PATH, OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY || "nemoclaw", - }), + NO_COLOR: "1", + CLICOLOR: "0", + CLICOLOR_FORCE: "0", + }, timeout: 60000, maxBuffer: 20 * 1024 * 1024, }) @@ -80,50 +83,48 @@ function isSandboxNotFound(output: string) { return /sandbox not found|status:\s*NotFound|not present in the live OpenShell gateway/i.test(output) } -function isGatewayRecoverable(output: string) { - return /Unknown gateway|Deploy it first|transport error|tcp connect error|Connection refused|invalid peer certificate|BadSignature/i.test(output) +function isNemoClawSandboxNotRegistered(output: string, sandboxName: string) { + return new RegExp(`Unknown command:\\s*${sandboxName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}`, "i").test(output) } -const NEMOCLAW_REGISTRY_PATH = path.join(process.env.HOME || "/tmp", ".nemoclaw", "sandboxes.json") - async function cleanupNemoClawSandbox(sandboxName: string) { + const startedAt = Date.now() + console.log(`[sandbox/delete] nemoclaw-cleanup:start sandbox=${sandboxName}`) try { - const raw = await readFile(NEMOCLAW_REGISTRY_PATH, "utf8") - const registry = JSON.parse(raw) - const sandboxes = registry && typeof registry === "object" && registry.sandboxes && typeof registry.sandboxes === "object" - ? registry.sandboxes - : {} - const existed = Object.prototype.hasOwnProperty.call(sandboxes, sandboxName) - if (existed) delete sandboxes[sandboxName] - const remaining = Object.keys(sandboxes) - const defaultSandbox = registry.defaultSandbox === sandboxName - ? remaining[0] || null - : (registry.defaultSandbox && sandboxes[registry.defaultSandbox] ? registry.defaultSandbox : remaining[0] || null) - const next = { ...registry, sandboxes, defaultSandbox } - await mkdir(path.dirname(NEMOCLAW_REGISTRY_PATH), { recursive: true, mode: 0o700 }) - await writeFile(NEMOCLAW_REGISTRY_PATH, `${JSON.stringify(next, null, 2)}\n`, { mode: 0o600 }) - return { - ok: true as const, - stdout: "", - stderr: "", - note: existed - ? "Pruned NemoClaw registry entry without destroying the shared OpenShell gateway." - : "NemoClaw registry already had no matching sandbox entry.", - } - } catch (error) { - const message = error instanceof Error ? error.message : String(error ?? "NemoClaw registry cleanup failed") - if (/ENOENT/.test(message)) { + const { stdout, stderr } = await execFileAsync(NEMOCLAW_BIN, [sandboxName, "destroy", "--yes"], { + cwd: NEMOCLAW_CWD, + env: { + ...process.env, + PATH: HOST_PATH, + OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY || "nemoclaw", + NO_COLOR: "1", + CLICOLOR: "0", + CLICOLOR_FORCE: "0", + }, + timeout: 90000, + maxBuffer: 20 * 1024 * 1024, + }) + console.log(`[sandbox/delete] nemoclaw-cleanup:done sandbox=${sandboxName} elapsedMs=${elapsedMs(startedAt)}`) + return { ok: true as const, stdout: String(stdout).trim(), stderr: String(stderr).trim() } + } catch (error: any) { + const message = error instanceof Error ? error.message : String(error ?? "NemoClaw cleanup failed") + const stdout = String(error?.stdout || "").trim() + const stderr = String(error?.stderr || "").trim() + const output = [message, stdout, stderr].filter(Boolean).join("\n") + if (isNemoClawSandboxNotRegistered(output, sandboxName)) { + console.log(`[sandbox/delete] nemoclaw-cleanup:already-gone sandbox=${sandboxName} elapsedMs=${elapsedMs(startedAt)}`) return { ok: true as const, - stdout: "", - stderr: "", - note: "NemoClaw registry file does not exist; skipped registry cleanup.", + stdout, + stderr, + note: "NemoClaw registry already had no matching sandbox.", } } + console.log(`[sandbox/delete] nemoclaw-cleanup:error sandbox=${sandboxName} elapsedMs=${elapsedMs(startedAt)} message=${message}`) return { ok: false as const, - stdout: "", - stderr: "", + stdout, + stderr, error: message, } } @@ -178,6 +179,7 @@ export async function POST(request: Request) { const result = await deleteSandbox(target.sandboxName) const deleteOutput = [result.error, result.stdout, result.stderr].filter(Boolean).join("\n") const openShellAlreadyGone = !result.ok && isSandboxNotFound(deleteOutput) + const cleanup = await cleanupNemoClawSandbox(target.sandboxName) if (!result.ok && !openShellAlreadyGone) { return NextResponse.json({ @@ -191,15 +193,10 @@ export async function POST(request: Request) { error: result.error, stdout: result.stdout, stderr: result.stderr, - recoverableGateway: isGatewayRecoverable(deleteOutput), - note: isGatewayRecoverable(deleteOutput) - ? "OpenShell gateway is unavailable or its trust state is broken. Repair gateway trust, then retry delete." - : "OpenShell delete failed before NemoClaw cleanup ran.", - }, { status: isGatewayRecoverable(deleteOutput) ? 503 : 500 }) + nemoclaw: cleanup, + }, { status: 500 }) } - const cleanup = await cleanupNemoClawSandbox(target.sandboxName) - if (!cleanup.ok) { return NextResponse.json({ ok: false, diff --git a/app/components/ConfigurationPanel.tsx b/app/components/ConfigurationPanel.tsx index eec1e1e..731f380 100644 --- a/app/components/ConfigurationPanel.tsx +++ b/app/components/ConfigurationPanel.tsx @@ -7,7 +7,6 @@ type EndpointProtocol = "" | "rest" type EndpointTls = "" | "terminate" | "passthrough" type EndpointEnforcement = "" | "enforce" | "audit" type EndpointAccess = "" | "read-only" | "read-write" | "full" -type CreateInferenceMode = "auto" | "vllm" | "nim" interface NetworkRule { method: string; path: string } interface NetworkEndpoint { host: string; port: string; protocol: EndpointProtocol; tls: EndpointTls; enforcement: EndpointEnforcement; access: EndpointAccess; rules: NetworkRule[] } @@ -88,9 +87,6 @@ export default function ConfigurationPanel({ sandboxId, mode = 'existing', onCre const [selectedBlueprint, setSelectedBlueprint] = useState('nemoclaw-blueprint') const [sandboxName, setSandboxName] = useState('') const [enableTailscale, setEnableTailscale] = useState(false) - const [createInferenceMode, setCreateInferenceMode] = useState("vllm") - const [createInferenceModel, setCreateInferenceModel] = useState("") - const [createNvidiaApiKey, setCreateNvidiaApiKey] = useState("") const [restoreFromBackup, setRestoreFromBackup] = useState(false) const [restoreArchive, setRestoreArchive] = useState(null) const [restorePath, setRestorePath] = useState('/sandbox') @@ -138,12 +134,7 @@ export default function ConfigurationPanel({ sandboxId, mode = 'existing', onCre if (mode === 'create') { if (!sandboxName.trim()) throw new Error('sandbox name is required') if (restoreFromBackup && !restoreArchive) throw new Error('backup archive is required when restore from backup is enabled') - const createInference = { - mode: createInferenceMode, - model: createInferenceModel.trim(), - apiKey: createInferenceMode === 'nim' ? createNvidiaApiKey.trim() : '', - } - const res = await fetch('/api/sandbox/create', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ blueprint: selectedBlueprint, sandboxName: sandboxName.trim(), enableTailscale, createInference, policy: assembledPolicy, preset: selectedPreset || null }) }) + const res = await fetch('/api/sandbox/create', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ blueprint: selectedBlueprint, sandboxName: sandboxName.trim(), enableTailscale, policy: assembledPolicy, preset: selectedPreset || null }) }) const data = await res.json() if (!res.ok) throw new Error([data.error, data.verification?.summary, data.verification?.error, data.stdout, data.stderr].filter(Boolean).join('\n\n')) const createdSandboxId = data.verification?.details?.id || data.verification?.details?.name || data.sandboxName @@ -197,76 +188,7 @@ export default function ConfigurationPanel({ sandboxId, mode = 'existing', onCre )} {loading ?
Loading policy…
:
- {mode === 'create' && ( -
-
-
Create Sandbox
-

Choose a template and enter a sandbox name.

-
-
- {blueprints.map((bp) => ( - - ))} -
-
- - setSandboxName(e.target.value)} placeholder={selectedBlueprint === 'nemoclaw-blueprint' ? 'my-assistant' : 'custom-sandbox'} className="mt-2 w-full rounded-sm border border-[var(--border-subtle)] bg-[var(--background)] px-3 py-2 text-xs font-mono text-[var(--foreground)]" /> -
- {activeBlueprint?.supportsTailscale && ( - - )} - {enableTailscale &&
Tailscale-enabled creation requires NVIDIA_API_KEY in the dashboard process environment.
} -
-
-
Inference at Create
-

Choose the provider NemoClaw should use while onboarding this sandbox.

-
-
- - - -
- {createInferenceMode !== 'auto' && ( -
-
- - setCreateInferenceModel(e.target.value)} placeholder={createInferenceMode === 'vllm' ? 'auto-detect from vLLM' : 'model name'} className="w-full rounded-sm border border-[var(--border-subtle)] bg-[var(--background-tertiary)] px-3 py-2 text-xs font-mono text-[var(--foreground)]" /> -
- {createInferenceMode === 'nim' && ( -
- - setCreateNvidiaApiKey(e.target.value)} placeholder="nvapi-..." className="w-full rounded-sm border border-[var(--border-subtle)] bg-[var(--background-tertiary)] px-3 py-2 text-xs font-mono text-[var(--foreground)]" /> -
- )} -
- )} -
-
- - {restoreFromBackup &&
setRestoreArchive(e.target.files?.[0] || null)} className="block w-full text-xs text-[var(--foreground-dim)] file:mr-3 file:rounded-sm file:border file:border-[var(--border-subtle)] file:bg-[var(--background-tertiary)] file:px-3 file:py-2 file:text-xs file:font-mono file:uppercase file:text-[var(--foreground)]" />
setRestorePath(e.target.value)} placeholder="/sandbox" className="w-full rounded-sm border border-[var(--border-subtle)] bg-[var(--background-tertiary)] px-3 py-2 text-xs font-mono text-[var(--foreground)]" />
} -
-
- )} + {mode === 'create' &&
Create Sandbox

Choose a template and enter a sandbox name.

{blueprints.map((bp) => )}
setSandboxName(e.target.value)} placeholder={selectedBlueprint === 'nemoclaw-blueprint' ? 'my-assistant' : 'custom-sandbox'} className="mt-2 w-full rounded-sm border border-[var(--border-subtle)] bg-[var(--background)] px-3 py-2 text-xs font-mono text-[var(--foreground)]" />
{activeBlueprint?.supportsTailscale && }{enableTailscale &&
Tailscale-enabled creation requires NVIDIA_API_KEY in the dashboard process environment.
}
{restoreFromBackup &&
setRestoreArchive(e.target.files?.[0] || null)} className="block w-full text-xs text-[var(--foreground-dim)] file:mr-3 file:rounded-sm file:border file:border-[var(--border-subtle)] file:bg-[var(--background-tertiary)] file:px-3 file:py-2 file:text-xs file:font-mono file:uppercase file:text-[var(--foreground)]" />
setRestorePath(e.target.value)} placeholder="/sandbox" className="w-full rounded-sm border border-[var(--border-subtle)] bg-[var(--background-tertiary)] px-3 py-2 text-xs font-mono text-[var(--foreground)]" />
}
}
Security Presets

Use a canned profile for new sandboxes or switch an existing sandbox policy baseline on the fly.

{activePreset &&
{activePreset.label}

{activePreset.summary}

}
Filesystem Policy
Static
setPolicy({ ...policy, filesystem_policy: { ...policy.filesystem_policy, read_only: v } })} placeholder="/usr\n/lib\n/etc" /> setPolicy({ ...policy, filesystem_policy: { ...policy.filesystem_policy, read_write: v } })} placeholder="/sandbox\n/tmp" />
Network Policies
Dynamic
diff --git a/app/components/SandboxList.tsx b/app/components/SandboxList.tsx index cbe1422..5f2f56d 100644 --- a/app/components/SandboxList.tsx +++ b/app/components/SandboxList.tsx @@ -1,5 +1,5 @@ "use client" -import { useCallback, useEffect, useState } from 'react' +import { useEffect, useState } from 'react' import type { ReactNode } from 'react' import ConfigurationPanel from './ConfigurationPanel' import SandboxArchivePanel from './SandboxArchivePanel' @@ -150,34 +150,33 @@ export default function SandboxList({ } }, [selectedSandboxId]) - const loadPermissionFeed = useCallback(async (sandbox: SandboxInventoryItem) => { - try { - const response = await fetch(`/api/sandbox/${encodeURIComponent(sandbox.id)}/permissions`, { cache: 'no-store' }) - const data = await response.json() - const feed = response.ok ? data.feed : { rejectedCount: 1, latest: { status: 'Unavailable', error: data.error } } - setPermissionFeeds((current) => ({ ...current, [sandbox.id]: feed })) - } catch (error) { - setPermissionFeeds((current) => ({ - ...current, - [sandbox.id]: { rejectedCount: 1, latest: { status: 'Unavailable', error: error instanceof Error ? error.message : 'Permission feed unavailable' } }, - })) - } - }, []) - useEffect(() => { if (sandboxes.length === 0) { setPermissionFeeds({}) return } - setPermissionFeeds((current) => Object.fromEntries( - Object.entries(current).filter(([sandboxId]) => sandboxes.some((sandbox) => sandbox.id === sandboxId)), - )) - }, [sandboxes]) - useEffect(() => { - if (!selectedSandbox || !openDrawers.policy || permissionFeeds[selectedSandbox.id]) return - loadPermissionFeed(selectedSandbox) - }, [loadPermissionFeed, openDrawers.policy, permissionFeeds, selectedSandbox]) + let active = true + const loadPermissionFeeds = async () => { + const entries = await Promise.all(sandboxes.map(async (sandbox) => { + try { + const response = await fetch(`/api/sandbox/${encodeURIComponent(sandbox.id)}/permissions`, { cache: 'no-store' }) + const data = await response.json() + return [sandbox.id, response.ok ? data.feed : { rejectedCount: 1, latest: { status: 'Unavailable', error: data.error } }] as const + } catch (error) { + return [sandbox.id, { rejectedCount: 1, latest: { status: 'Unavailable', error: error instanceof Error ? error.message : 'Permission feed unavailable' } }] as const + } + })) + if (active) setPermissionFeeds(Object.fromEntries(entries)) + } + + loadPermissionFeeds() + const interval = window.setInterval(loadPermissionFeeds, 12000) + return () => { + active = false + window.clearInterval(interval) + } + }, [sandboxes]) useEffect(() => { let active = true @@ -213,31 +212,27 @@ export default function SandboxList({ } } - const restartSandboxRuntime = async () => { + const restartSandbox = async () => { if (!selectedSandbox || restartInProgress) return try { setRestartInProgress(true) - setDashboardMessage(`Restarting OpenClaw runtime for ${selectedSandbox.name}...`) + setDashboardMessage(`Restarting sandbox ${selectedSandbox.name}...`) const response = await fetch(`/api/sandbox/${encodeURIComponent(selectedSandbox.id)}/restart`, { method: 'POST', }) const data = await response.json() - if (!response.ok) throw new Error(data.error || data.note || 'Failed to restart OpenClaw runtime') - setDashboardMessage(data.note || `OpenClaw runtime restarted for ${selectedSandbox.name}.`) + if (!response.ok) throw new Error(data.error || data.note || 'Failed to restart sandbox') + setDashboardMessage(data.note || `Sandbox ${selectedSandbox.name} restarted.`) await onInventoryRefresh() } catch (error) { - setDashboardMessage(error instanceof Error ? error.message : 'Failed to restart OpenClaw runtime.') + setDashboardMessage(error instanceof Error ? error.message : 'Failed to restart sandbox.') } finally { setRestartInProgress(false) } } const toggleDrawer = (key: DrawerKey) => { - const opening = !openDrawers[key] setOpenDrawers((current) => ({ ...current, [key]: !current[key] })) - if (key === 'policy' && opening && selectedSandbox) { - loadPermissionFeed(selectedSandbox) - } } const sandboxCanAccessMcpServer = (sandbox: SandboxInventoryItem, server: McpServerAccess) => { @@ -274,25 +269,20 @@ export default function SandboxList({ } } - const syncMcpManifest = async (sandbox: SandboxInventoryItem, action: 'sync' | 'revoke' = 'sync') => { + const syncMcpManifest = async (sandbox: SandboxInventoryItem) => { try { setMcpSyncing(true) - setMcpMessage(action === 'revoke' ? `Revoking MCP broker config for ${sandbox.name}...` : `Issuing MCP broker config for ${sandbox.name}...`) + setMcpMessage(`Issuing MCP broker config for ${sandbox.name}...`) const response = await fetch(`/api/sandbox/${encodeURIComponent(sandbox.id)}/mcp`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ sandboxName: sandbox.name, action }), + body: JSON.stringify({ sandboxName: sandbox.name }), }) const data = await response.json() - if (!response.ok) throw new Error(data.error || 'Failed to update MCP broker config') - const networkNote = data.network?.approved?.length - ? ` Approved ${data.network.approved.length} broker network rule${data.network.approved.length === 1 ? '' : 's'}.` - : data.network?.rejected?.length - ? ` Removed ${data.network.rejected.length} broker network rule${data.network.rejected.length === 1 ? '' : 's'}.` - : '' - setMcpMessage(`${data.note || 'MCP broker config updated.'}${networkNote}`) + if (!response.ok) throw new Error(data.error || 'Failed to issue MCP broker config') + setMcpMessage(data.note || 'MCP broker config issued.') } catch (error) { - setMcpMessage(error instanceof Error ? error.message : 'Failed to update MCP broker config') + setMcpMessage(error instanceof Error ? error.message : 'Failed to issue MCP broker config') } finally { setMcpSyncing(false) } @@ -305,7 +295,7 @@ export default function SandboxList({ enabled: true, accessMode: server.accessMode === 'allow_all' ? 'allow_all' : 'allow_only', allowedSandboxIds: Array.from(current), - }, `${server.name} enabled for ${sandbox.name}.`) + }, `${server.name} enabled for ${sandbox.name}.`).then(() => syncMcpManifest(sandbox)) } const revokeMcpForSandbox = (sandbox: SandboxInventoryItem, server: McpServerAccess) => { @@ -320,7 +310,7 @@ export default function SandboxList({ return updateMcpServerAccess(server, { accessMode: 'allow_only', allowedSandboxIds: Array.from(current), - }, `${server.name} revoked from ${sandbox.name}.`) + }, `${server.name} revoked from ${sandbox.name}.`).then(() => syncMcpManifest(sandbox)) } const resolvePermissionRequest = async (sandbox: SandboxInventoryItem, action: 'approve' | 'reject', chunkId: string) => { @@ -360,25 +350,21 @@ export default function SandboxList({
) : ( <> -