the universal sandbox runtime for agents and humans. pocketenv.io
sandbox openclaw agent claude-code vercel-sandbox deno-sandbox cloudflare-sandbox atproto sprites daytona
7
fork

Configure Feed

Select the types of activity you want to include in your feed.

Persist sandbox initialization state in atom

Replace local ref with initializedSandboxesAtom to track whether a
sandbox's initialCommand has been fired, ensuring it persists across
component unmounts and remounts.

+10 -4
+4
apps/web/src/atoms/sessions.ts
··· 1 1 import { atom } from "jotai"; 2 2 3 3 export const sessionsAtom = atom<Record<string, string>>({}); 4 + 5 + // Tracks which sandboxIds have already fired their initialCommand 6 + // Persists across component unmount/remount since it lives outside the component 7 + export const initializedSandboxesAtom = atom<Record<string, boolean>>({});
+6 -4
apps/web/src/components/terminal/CloudflareTerminal.tsx
··· 7 7 import { useTerminalTokenQuery } from "../../hooks/useTerminal"; 8 8 import { createId } from "@paralleldrive/cuid2"; 9 9 import { useAtom } from "jotai"; 10 - import { sessionsAtom } from "../../atoms/sessions"; 10 + import { sessionsAtom, initializedSandboxesAtom } from "../../atoms/sessions"; 11 11 import { useLocation, useSearch } from "@tanstack/react-router"; 12 12 13 13 const darkTheme = { ··· 81 81 }: TerminalContentProps) { 82 82 const fitAddonRef = useRef<FitAddon | null>(null); 83 83 const sandboxAddonRef = useRef<SandboxAddon | null>(null); 84 - const initialCommandFiredRef = useRef(false); 85 84 const { data: terminalToken, isLoading } = useTerminalTokenQuery(); 86 85 const [sessions, setSessions] = useAtom(sessionsAtom); 86 + const [initializedSandboxes, setInitializedSandboxes] = useAtom( 87 + initializedSandboxesAtom, 88 + ); 87 89 const location = useLocation(); 88 90 const params = useSearch({ 89 91 from: location.pathname.startsWith("/sandbox/") ··· 147 149 if ( 148 150 state === "connected" && 149 151 initialCommand && 150 - !initialCommandFiredRef.current 152 + !initializedSandboxes[sandboxId] 151 153 ) { 152 - initialCommandFiredRef.current = true; 154 + setInitializedSandboxes((prev) => ({ ...prev, [sandboxId]: true })); 153 155 setTimeout(() => instance.paste(initialCommand + "\n"), 300); 154 156 } 155 157 if (state === "disconnected") {