(env: SandboxComputerBindings, owner: ComputerOwner)
| 24 | } |
| 25 | |
| 26 | export async function getOwnerComputer(env: SandboxComputerBindings, owner: ComputerOwner): Promise<ComputerSandbox> { |
| 27 | const key = `computer-v3:${ownerKey(owner)}`; |
| 28 | if (env.getComputerSandbox) return env.getComputerSandbox(key); |
| 29 | if (!env.CLOUDBOX_SANDBOX) throw new Error("CLOUDBOX_SANDBOX binding is unavailable"); |
| 30 | // Keep the Sandbox SDK out of unit-test module evaluation: its upstream |
| 31 | // containers package is Workers/bundler-oriented rather than Node ESM-safe. |
| 32 | const { getSandbox } = await import("@cloudflare/sandbox"); |
| 33 | return getSandbox(env.CLOUDBOX_SANDBOX as never, key, { |
| 34 | containerTimeouts: { instanceGetTimeoutMS: 120_000, portReadyTimeoutMS: 240_000 }, |
| 35 | transport: "rpc", |
| 36 | }) as unknown as ComputerSandbox; |
| 37 | } |
| 38 | |
| 39 | export function assertComputerPath(path: string): void { |
| 40 | if (!path.startsWith(`${COMPUTER_HOME}/`) || path.includes("/../") || path.endsWith("/..") || path.includes("\0")) { |
no test coverage detected