| What you want | Use |
| Resize once, predictably | scale() |
| Track memory pressure automatically | set_autoscale() |
| Freeze the current size | set_scaling_lock() |
scale() disables autoscale on the sandbox as a side effect — explicit user intent overrides the loop. Re-enable with set_autoscale(enabled=True, ...) after if you want.scale() and set_autoscale(enabled=True) raise ScalingLockedError. Unlocking does NOT auto-re-enable autoscale.PlanLimitError.sandbox.scale(memory_mb)body memory_mbintrequireddict with sandboxID, memoryMB, cpuPercent.ScalingLockedError — sandbox has a scaling lock active.PlanLimitError — memory_mb exceeds the org's plan cap.1234567891011from opencomputer import Sandbox, ScalingLockedError, PlanLimitError sandbox = await Sandbox.connect("sb-abc123") try: result = await sandbox.scale(memory_mb=8192) print(f"scaled to {result['memoryMB']}MB / {result['cpuPercent']}% CPU") except ScalingLockedError: print("sandbox is locked — unlock to scale") except PlanLimitError: print("upgrade required for larger instances")
sandbox.set_autoscale(enabled, *, min_memory_mb=None, max_memory_mb=None)body enabledboolrequiredbody min_memory_mbintenabled=True.body max_memory_mbintenabled=True. Must be ≥ min_memory_mb.dict with sandboxID, enabled, minMemoryMB, maxMemoryMB.ScalingLockedError — sandbox has a scaling lock active.PlanLimitError — max_memory_mb exceeds the org's plan cap.enabled=True, the platform watches the sandbox's memory pressure and resizes it within the bounds:12345await sandbox.set_autoscale( enabled=True, min_memory_mb=1024, max_memory_mb=16384, )
1await sandbox.set_autoscale(enabled=False)
sandbox.get_autoscale()dict with sandboxID, enabled, minMemoryMB, maxMemoryMB.123cfg = await sandbox.get_autoscale() if cfg["enabled"]: print(f"autoscale {cfg['minMemoryMB']}–{cfg['maxMemoryMB']} MB")
sandbox.set_scaling_lock(locked)body lockedboolrequiredTrue to freeze, False to allow scaling again.dict with sandboxID, locked.scale() raises ScalingLockedError.set_autoscale(enabled=True) raises ScalingLockedError.set_autoscale(enabled=True, ...) explicitly if you want it back.1234567# Pin a sandbox at its current size during a critical workload await sandbox.set_scaling_lock(True) # ... # Allow scaling again after await sandbox.set_scaling_lock(False)
sandbox.get_scaling_lock()dict with sandboxID, locked.ScalingLockedErrorcode = "scaling_locked" for parity with the HTTP API's error code.1234567from opencomputer import ScalingLockedError try: await sandbox.scale(memory_mb=8192) except ScalingLockedError: # unlock first, or surface to user ...
PlanLimitError