Skip to content
Closed
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
11 changes: 8 additions & 3 deletions packages/backends/src/sandbox/remote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ import type {SandboxBackend} from './backend';
// How long a request may take beyond what the command itself may.
const REQUEST_MS = 30_000;

// How long making or waking a sandbox may take: a boot on a small machine, the first after a
// start with the software to fetch, runs to a minute or two; and a command may wake the sandbox
// it runs in first.
const BOOT_MS = 180_000;

export type RemoteSandboxOptions = {
url: string;
token: string;
Expand Down Expand Up @@ -94,10 +99,10 @@ export function remoteSandboxBackend({url, token, headers}: RemoteSandboxOptions

return {
id: 'remote',
create: async (sandbox) => (await call('POST', '/sandboxes', createSandboxBodySchema.parse(sandbox), sandboxRefSchema)).map(({ref}) => ref),
exec: (ref, command) => call('POST', at(ref, '/exec'), execSandboxBodySchema.parse(command), sandboxOutputSchema, command.timeoutMs + REQUEST_MS),
create: async (sandbox) => (await call('POST', '/sandboxes', createSandboxBodySchema.parse(sandbox), sandboxRefSchema, BOOT_MS)).map(({ref}) => ref),
exec: (ref, command) => call('POST', at(ref, '/exec'), execSandboxBodySchema.parse(command), sandboxOutputSchema, command.timeoutMs + BOOT_MS),
sleep: async (ref) => (await call('POST', at(ref, '/sleep'), null, sandboxRefSchema)).map((answer) => answer.ref),
wake: async (ref) => (await call('POST', at(ref, '/wake'), null, sandboxRefSchema)).map((answer) => answer.ref),
wake: async (ref) => (await call('POST', at(ref, '/wake'), null, sandboxRefSchema, BOOT_MS)).map((answer) => answer.ref),
destroy: async (ref) => (await call('DELETE', at(ref), null, sandboxDestroyedSchema)).map(() => undefined),
};
}
Loading