@@ -9,24 +9,6 @@ type ProcessCreateSandboxInput = {
99} ;
1010type ProcessCreateSandboxResult = SandboxCreatedResponse & { runId ?: string } ;
1111
12- /**
13- * Returns a valid (non-expired) snapshot ID for the account, or undefined.
14- *
15- * @param accountId - The account to look up
16- * @returns The snapshot ID if it exists and has not expired
17- */
18- async function getValidSnapshotId ( accountId : string ) : Promise < string | undefined > {
19- const accountSnapshots = await selectAccountSnapshots ( accountId ) ;
20- const snapshot = accountSnapshots [ 0 ] ;
21- if ( ! snapshot ?. snapshot_id ) return undefined ;
22-
23- if ( snapshot . expires_at && new Date ( snapshot . expires_at ) < new Date ( ) ) {
24- return undefined ;
25- }
26-
27- return snapshot . snapshot_id ;
28- }
29-
3012/**
3113 * Shared domain logic for creating a sandbox and optionally running a prompt.
3214 * Used by both POST /api/sandboxes handler and the prompt_sandbox MCP tool.
@@ -39,24 +21,14 @@ export async function processCreateSandbox(
3921) : Promise < ProcessCreateSandboxResult > {
4022 const { accountId, prompt } = input ;
4123
42- const snapshotId = await getValidSnapshotId ( accountId ) ;
43-
44- let result ;
24+ // Get account's most recent snapshot if available
25+ const accountSnapshots = await selectAccountSnapshots ( accountId ) ;
26+ const snapshotId = accountSnapshots [ 0 ] ?. snapshot_id ;
4527
46- if ( snapshotId ) {
47- try {
48- const createResult = await createSandbox ( {
49- source : { type : "snapshot" , snapshotId } ,
50- } ) ;
51- result = createResult . response ;
52- } catch {
53- const freshResult = await createSandbox ( { } ) ;
54- result = freshResult . response ;
55- }
56- } else {
57- const freshResult = await createSandbox ( { } ) ;
58- result = freshResult . response ;
59- }
28+ // Create sandbox (from snapshot if valid, otherwise fresh)
29+ const { response : result } = await createSandbox (
30+ snapshotId ? { source : { type : "snapshot" , snapshotId } } : { } ,
31+ ) ;
6032
6133 await insertAccountSandbox ( {
6234 account_id : accountId ,
0 commit comments