| What you want | Use |
| Resize once, predictably | scale() |
| Track memory pressure automatically | setAutoscale() |
| Freeze the current size | setScalingLock() |
scale() disables autoscale on the sandbox as a side effect — explicit user intent overrides the loop. Re-enable autoscale with setAutoscale({ enabled: true, ... }) after if you want.scale() and setAutoscale({ enabled: true }) reject with ScalingLockedError. Unlocking does NOT auto-re-enable autoscale.PlanLimitError.sandbox.scale(opts)body memoryMBnumberrequiredPromise<{ sandboxID: string; memoryMB: number; cpuPercent: number }>ScalingLockedError — sandbox has a scaling lock active.PlanLimitError — memoryMB exceeds the org's plan cap.12345678910111213141516import { Sandbox, ScalingLockedError, PlanLimitError } from "@opencomputer/sdk"; const sandbox = await Sandbox.connect("sb-abc123"); try { const result = await sandbox.scale({ memoryMB: 8192 }); console.log(`scaled to ${result.memoryMB}MB / ${result.cpuPercent}% CPU`); } catch (err) { if (err instanceof ScalingLockedError) { console.warn("sandbox is locked — unlock to scale"); } else if (err instanceof PlanLimitError) { console.warn("upgrade required for larger instances"); } else { throw err; } }
sandbox.setAutoscale(opts)body enabledbooleanrequiredbody minMemoryMBnumberenabled=true.body maxMemoryMBnumberenabled=true. Must be ≥ minMemoryMB.Promise<{ sandboxID: string; enabled: boolean; minMemoryMB: number; maxMemoryMB: number }>ScalingLockedError — sandbox has a scaling lock active.PlanLimitError — maxMemoryMB exceeds the org's plan cap.enabled=true, the platform watches the sandbox's memory pressure and resizes it within the bounds:12345await sandbox.setAutoscale({ enabled: true, minMemoryMB: 1024, maxMemoryMB: 16384, });
1await sandbox.setAutoscale({ enabled: false });
sandbox.getAutoscale()Promise<{ sandboxID: string; enabled: boolean; minMemoryMB: number; maxMemoryMB: number }>1234const cfg = await sandbox.getAutoscale(); if (cfg.enabled) { console.log(`autoscale ${cfg.minMemoryMB}–${cfg.maxMemoryMB} MB`); }
sandbox.setScalingLock(locked)body lockedbooleanrequiredtrue to freeze, false to allow scaling again.Promise<{ sandboxID: string; locked: boolean }>scale() rejects with ScalingLockedError.setAutoscale({ enabled: true }) rejects with ScalingLockedError.setAutoscale({ enabled: true, ... }) explicitly if you want it back.1234567// Pin a sandbox at its current size during a critical workload await sandbox.setScalingLock(true); // ... // Allow scaling again after await sandbox.setScalingLock(false);
sandbox.getScalingLock()Promise<{ sandboxID: string; locked: boolean }>ScalingLockedErrorcode property of "scaling_locked" for parity with the HTTP API's error code.123456789import { ScalingLockedError } from "@opencomputer/sdk"; try { await sandbox.scale({ memoryMB: 8192 }); } catch (err) { if (err instanceof ScalingLockedError) { // unlock first, or surface to user } }
PlanLimitError