Skip to content

An open-source, faster Devin alternative

TypeScript

revert docs change for now

Brian Reardon26856f8fb209
diff --git a/docs/api-reference/checkpoints/fork.mdx b/docs/api-reference/checkpoints/fork.mdx
index bf35baed..69ffab92 100644
--- a/docs/api-reference/checkpoints/fork.mdx
+++ b/docs/api-reference/checkpoints/fork.mdx
@@ -22,7 +22,7 @@ Create a new sandbox from a checkpoint.
</ParamField>
<ParamField body="memoryMB" type="integer">
- Memory for the forked sandbox, in MB. Clamped to a valid range: the floor is the checkpoint's own memory (a fork can't start smaller than the snapshot it restores, so a smaller value is ignored) and the ceiling is 8192 (8 GB; larger values are capped). The `memoryMB` field in the response reports the effective value after clamping.
+ Memory for the forked sandbox, in MB. Clamped to a valid range: the floor is the checkpoint's own memory (a fork can't start smaller than the snapshot it restores, so a smaller value is ignored) and the ceiling is 16384 (16 GB; larger values are capped). The `memoryMB` field in the response reports the effective value after clamping.
</ParamField>
<ResponseExample>
diff --git a/docs/api-reference/sandboxes/create.mdx b/docs/api-reference/sandboxes/create.mdx
index e027f702..42d32dd7 100644
--- a/docs/api-reference/sandboxes/create.mdx
+++ b/docs/api-reference/sandboxes/create.mdx
@@ -29,13 +29,6 @@ The 1 GB tier provides 1 vCPU on a best-effort basis. For guaranteed CPU allocat
If both `cpuCount` and `memoryMB` are provided, they must match a platform tier.
-<Note>
- `memoryMB` is the only opportunity to size a sandbox: the size is fixed for the
- sandbox's lifetime and cannot be changed afterwards. A size outside the
- supported tiers is rejected rather than rounded down, so you are never quietly
- given less than you asked for. See [Sizing](/sandboxes/sizing).
-</Note>
-
<ParamField body="envs" type="object">
Environment variables as key-value pairs
</ParamField>
diff --git a/docs/docs.json b/docs/docs.json
index e88f5d43..740bbb43 100644
--- a/docs/docs.json
+++ b/docs/docs.json
@@ -102,7 +102,7 @@
"sandboxes/patches",
"sandboxes/preview-urls",
"sandboxes/webhooks",
- "sandboxes/sizing",
+ "sandboxes/elasticity",
"sandboxes/burst-sandboxes",
{
"group": "Usage",
@@ -154,6 +154,7 @@
"pages": [
"reference/typescript-sdk/overview",
"reference/typescript-sdk/sandbox",
+ "reference/typescript-sdk/scaling",
{
"group": "Usage & Tags",
"tag": "Preview",
@@ -173,6 +174,7 @@
"pages": [
"reference/python-sdk/overview",
"reference/python-sdk/sandbox",
+ "reference/python-sdk/scaling",
"reference/python-sdk/exec",
"reference/python-sdk/filesystem",
"reference/python-sdk/pty",
@@ -186,6 +188,7 @@
"pages": [
"reference/cli/overview",
"reference/cli/sandbox",
+ "reference/cli/scaling",
"reference/cli/exec",
"reference/cli/shell",
"reference/cli/checkpoint",
diff --git a/docs/guides/browser-automation.mdx b/docs/guides/browser-automation.mdx
index 5c3a0ce6..f82524d8 100644
--- a/docs/guides/browser-automation.mdx
+++ b/docs/guides/browser-automation.mdx
@@ -233,7 +233,7 @@ The profile lives on the data disk, which survives sandbox hibernation. For cros
## Resource and concurrency limits
-- **Memory per VM** — default is ~1GB. Each headless Chromium uses ~300-500MB; headed full Chromium uses ~500-800MB. Pass `memoryMB: 8192` to `Sandbox.create` for browser-heavy work.
+- **Memory per VM** — default is ~1GB. Each headless Chromium uses ~300-500MB; headed full Chromium uses ~500-800MB. Pass `memoryMB: 16384` to `Sandbox.create` for browser-heavy work.
- **File descriptors** — the default `nofile` limit of 1024 is too low for Chromium (which opens hundreds of FDs). Launch the server process under `sudo bash -c "ulimit -n 65535 && exec ..."` to raise it.
- **Concurrency** — with default memory, run 2-3 browsers concurrently per sandbox. With 16GB and proper limits, 5+ works cleanly.
diff --git a/docs/how-it-works.mdx b/docs/how-it-works.mdx
index 255e68bd..c229f8d5 100644
--- a/docs/how-it-works.mdx
+++ b/docs/how-it-works.mdx
@@ -65,7 +65,7 @@ See [Templates](/sandboxes/templates) for the full guide.
## Elasticity
-A sandbox's memory is chosen when it is created and stays fixed for its lifetime, with CPU allocated proportionally. See [Sizing](/sandboxes/sizing) for the available tiers.
+Sandboxes can scale memory at runtime via an internal metadata endpoint (`http://169.254.169.254/v1/scale`) accessible from inside the VM. CPU scales proportionally. This lets workloads request more resources before heavy tasks and release them after. See [Elasticity](/sandboxes/elasticity) for details.
## Networking
diff --git a/docs/quickstart.mdx b/docs/quickstart.mdx
index 2acf9a03..d08f2bed 100644
--- a/docs/quickstart.mdx
+++ b/docs/quickstart.mdx
@@ -60,8 +60,8 @@ Your sandboxes stay alive as long as you need them. They don't shut down after a
## Next Steps
<CardGroup cols={2}>
- <Card title="Sizing" icon="gauge-high" href="/sandboxes/sizing">
- Pick the memory and CPU your workload needs at create time
+ <Card title="Elastic Compute" icon="gauge-high" href="/sandboxes/elasticity">
+ Scale memory and CPU at runtime based on workload
</Card>
<Card title="Upload & Download Files" icon="file-arrow-up" href="/sandboxes/working-with-files">
Read, write, and transfer files to and from sandboxes
diff --git a/docs/reference/cli/sandbox.mdx b/docs/reference/cli/sandbox.mdx
index 845a3bfc..6f675a9a 100644
--- a/docs/reference/cli/sandbox.mdx
+++ b/docs/reference/cli/sandbox.mdx
@@ -100,7 +100,7 @@ oc sandbox set-timeout sb-abc123 600
---
-A sandbox's size is chosen at create with `--memory`; see [Sizing](/sandboxes/sizing).
+For commands that resize a sandbox or freeze its size — `scale`, `autoscale`, `lock`, `unlock`, `lock-status` — see [Scaling](/reference/cli/scaling).
---
diff --git a/docs/reference/cli/scaling.mdx b/docs/reference/cli/scaling.mdx
new file mode 100644
index 00000000..62f42815
--- /dev/null
+++ b/docs/reference/cli/scaling.mdx
@@ -0,0 +1,121 @@
+---
+title: "oc sandbox scaling"
+description: "Resize sandboxes, configure autoscale, and manage scaling locks from the CLI"
+---
+
+The CLI groups three related actions for sizing a sandbox:
+
+| Command | What it does |
+| --- | --- |
+| [`oc sandbox autoscale`](#oc-sandbox-autoscale-id) | Turn the platform autoscaler on/off and inspect its config |
+| [`oc sandbox scale`](#oc-sandbox-scale-id-memory-mb) | Manually resize once |
+| [`oc sandbox lock`](#oc-sandbox-lock-id) / [`unlock`](#oc-sandbox-unlock-id) / [`lock-status`](#oc-sandbox-lock-status-id) | Freeze or unfreeze the current size |
+
+CPU follows memory per the platform's tier table; you don't pick CPU separately.
+
+For the underlying concepts and how these three modes interact, see the [Elasticity](/sandboxes/elasticity) guide.
+
+---
+
+## `oc sandbox autoscale <id>`
+
+Configure or inspect per-sandbox autoscale. [HTTP API →](/api-reference/sandboxes/autoscale)
+
+Run with no flags to print the current configuration:
+
+```bash
+oc sandbox autoscale sb-abc123
+# Autoscale enabled for sb-abc123 (1024–16384 MB)
+```
+
+Enable with bounds:
+
+```bash
+oc sandbox autoscale sb-abc123 --on --min 1024 --max 16384
+```
+
+Disable:
+
+```bash
+oc sandbox autoscale sb-abc123 --off
+```
+
+When enabled, the platform watches memory pressure and resizes the sandbox between `--min` and `--max`:
+
+- **Scale up** on a single 1-min sample above 75 % memory utilization. Cooldown 60 s between up-scales.
+- **Scale down** only when the 1-min, 5-min, AND 15-min averages all sit below 25 %. Cooldown 5 min between down-scales.
+
+The asymmetry is deliberate: rapid response when the user notices lag, conservative shrink after sustained idle.
+
+**Flags**
+
+| Flag | Description |
+| --- | --- |
+| `--on` | Enable autoscale (requires `--min` and `--max`). |
+| `--off` | Disable autoscale. Mutually exclusive with `--on`. |
+| `--min N` | Minimum memory in MB. |
+| `--max N` | Maximum memory in MB. Must be ≥ `--min`. |
+
+**Errors**
+
+- `scaling_locked` — the sandbox has a scaling lock active. Run `oc sandbox unlock <id>` first.
+- `402 Payment Required` — `--max` exceeds your plan cap.
+
+---
+
+## `oc sandbox scale <id> <memory-mb>`
+
+Manually resize a sandbox to a specific memory tier. [HTTP API →](/api-reference/sandboxes/scale)
+
+```bash
+oc sandbox scale sb-abc123 8192
+# Scaled sb-abc123 to 8192MB / 400% CPU
+```
+
+A manual scale **disables autoscale** on this sandbox as a side effect — explicit intent overrides the loop. Re-enable with `oc sandbox autoscale --on` if you want size to track load again.
+
+**Errors**
+
+- `scaling_locked` — the sandbox has a scaling lock active. Run `oc sandbox unlock <id>` first.
+- `402 Payment Required` — requested size exceeds your plan cap.
+
+---
+
+## `oc sandbox lock <id>`
+
+Pin a sandbox at its current size. [HTTP API →](/api-reference/sandboxes/scaling-lock)
+
+```bash
+oc sandbox lock sb-abc123
+# Sandbox sb-abc123 locked (scaling disabled)
+```
+
+While locked:
+
+- `oc sandbox scale` is rejected with `scaling_locked`.
+- `oc sandbox autoscale --on` is rejected with `scaling_locked`.
+- The platform autoscaler skips the sandbox entirely.
+
+Locking **also** disables autoscale (single knob — "I don't want this scaling, period"). Unlocking does NOT re-enable autoscale; run `oc sandbox autoscale --on` explicitly if you want it back.
+
+---
+
+## `oc sandbox unlock <id>`
+
+Clear the scaling lock.
+
+```bash
+oc sandbox unlock sb-abc123
+# Sandbox sb-abc123 unlocked
+```
+
+---
+
+## `oc sandbox lock-status <id>`
+
+Print the current scaling-lock state.
+
+```bash
+oc sandbox lock-status sb-abc123
+# Sandbox sb-abc123 is unlocked
+```
diff --git a/docs/reference/python-sdk/scaling.mdx b/docs/reference/python-sdk/scaling.mdx
new file mode 100644
index 00000000..b8138a6f
--- /dev/null
+++ b/docs/reference/python-sdk/scaling.mdx
@@ -0,0 +1,171 @@
+---
+title: "Scaling"
+description: "Resize a sandbox manually, autoscale on memory pressure, or freeze its resources."
+---
+
+OpenComputer sandboxes can change size at runtime. There are three knobs:
+
+| What you want | Use |
+| --- | --- |
+| Resize once, predictably | [`scale()`](#sandbox-scale-memory-mb) |
+| Track memory pressure automatically | [`set_autoscale()`](#sandbox-set-autoscale) |
+| Freeze the current size | [`set_scaling_lock()`](#sandbox-set-scaling-lock-locked) |
+
+CPU follows memory per the platform's tier table. You don't pick CPU separately.
+
+## How the three interact
+
+- **Manual `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.
+- **Setting a scaling lock** disables autoscale at the same time (single knob: "I don't want this scaling, period"). While locked, both `scale()` and `set_autoscale(enabled=True)` raise `ScalingLockedError`. Unlocking does NOT auto-re-enable autoscale.
+- **Plan caps** apply everywhere. Free-tier orgs are capped at 4 GB. Calls above the cap raise `PlanLimitError`.
+
+---
+
+## `sandbox.scale(memory_mb)`
+
+Manually resize the sandbox. [HTTP API →](/api-reference/sandboxes/scale)
+
+<ParamField body="memory_mb" type="int" required>
+ Target memory in MB.
+</ParamField>
+
+**Returns:** `dict` with `sandboxID`, `memoryMB`, `cpuPercent`.
+
+**Raises:**
+
+- `ScalingLockedError` — sandbox has a scaling lock active.
+- `PlanLimitError` — `memory_mb` exceeds the org's plan cap.
+
+```python
+from 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)`
+
+Enable or disable per-sandbox autoscale.
+
+<ParamField body="enabled" type="bool" required>
+ Whether autoscale should be active.
+</ParamField>
+
+<ParamField body="min_memory_mb" type="int">
+ Lower bound when `enabled=True`.
+</ParamField>
+
+<ParamField body="max_memory_mb" type="int">
+ Upper bound when `enabled=True`. Must be ≥ `min_memory_mb`.
+</ParamField>
+
+**Returns:** `dict` with `sandboxID`, `enabled`, `minMemoryMB`, `maxMemoryMB`.
+
+**Raises:**
+
+- `ScalingLockedError` — sandbox has a scaling lock active.
+- `PlanLimitError` — `max_memory_mb` exceeds the org's plan cap.
+
+When `enabled=True`, the platform watches the sandbox's memory pressure and resizes it within the bounds:
+
+- **Scale up** on a single 1-min sample above 75% memory utilization. Cooldown 60s between up-scales.
+- **Scale down** only when 1-min, 5-min, AND 15-min averages all sit below 25%. Cooldown 5 min between down-scales.
+
+The asymmetry matches user perception: rapid response when the user notices lag, conservative shrink after sustained idle. The 15-min window is the dominant constraint on shrink, so a sandbox that briefly idles and resumes won't sawtooth.
+
+```python
+await sandbox.set_autoscale(
+ enabled=True,
+ min_memory_mb=1024,
+ max_memory_mb=16384,
+)
+```
+
+To turn off:
+
+```python
+await sandbox.set_autoscale(enabled=False)
+```
+
+---
+
+## `sandbox.get_autoscale()`
+
+Get the current autoscale configuration.
+
+**Returns:** `dict` with `sandboxID`, `enabled`, `minMemoryMB`, `maxMemoryMB`.
+
+```python
+cfg = await sandbox.get_autoscale()
+if cfg["enabled"]:
+ print(f"autoscale {cfg['minMemoryMB']}–{cfg['maxMemoryMB']} MB")
+```
+
+---
+
+## `sandbox.set_scaling_lock(locked)`
+
+Lock or unlock the sandbox's resources against any size change.
+
+<ParamField body="locked" type="bool" required>
+ `True` to freeze, `False` to allow scaling again.
+</ParamField>
+
+**Returns:** `dict` with `sandboxID`, `locked`.
+
+While locked:
+
+- `scale()` raises `ScalingLockedError`.
+- `set_autoscale(enabled=True)` raises `ScalingLockedError`.
+- The platform autoscaler skips this sandbox entirely.
+
+Locking ALSO disables autoscale (single knob — "I don't want this scaling"). Unlocking does **not** re-enable autoscale; call `set_autoscale(enabled=True, ...)` explicitly if you want it back.
+
+```python
+# 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()`
+
+Get the current scaling-lock state.
+
+**Returns:** `dict` with `sandboxID`, `locked`.
+
+---
+
+## Errors
+
+### `ScalingLockedError`
+
+Raised when the sandbox has a scaling lock active. Has a class attribute `code = "scaling_locked"` for parity with the HTTP API's error code.
+
+```python
+from opencomputer import ScalingLockedError
+
+try:
+ await sandbox.scale(memory_mb=8192)
+except ScalingLockedError:
+ # unlock first, or surface to user
+ ...
+```
+
+### `PlanLimitError`
+
+Raised when the requested size exceeds the org's plan cap. The HTTP API returns 402 Payment Required for this case.
diff --git a/docs/reference/typescript-sdk/scaling.mdx b/docs/reference/typescript-sdk/scaling.mdx
new file mode 100644
index 00000000..0b01de58
--- /dev/null
+++ b/docs/reference/typescript-sdk/scaling.mdx
@@ -0,0 +1,179 @@
+---
+title: "Scaling"
+description: "Resize a sandbox manually, autoscale on memory pressure, or freeze its resources."
+---
+
+OpenComputer sandboxes can change size at runtime. There are three knobs:
+
+| What you want | Use |
+| --- | --- |
+| Resize once, predictably | [`scale()`](#sandbox-scale-opts) |
+| Track memory pressure automatically | [`setAutoscale()`](#sandbox-setautoscale-opts) |
+| Freeze the current size | [`setScalingLock()`](#sandbox-setscalinglock-locked) |
+
+CPU follows memory per the platform's tier table. You don't pick CPU separately.
+
+## How the three interact
+
+- **Manual `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.
+- **Setting a scaling lock** disables autoscale at the same time (single-knob: "I don't want this scaling, period"). While locked, both `scale()` and `setAutoscale({ enabled: true })` reject with `ScalingLockedError`. Unlocking does NOT auto-re-enable autoscale.
+- **Plan caps** apply everywhere. Free-tier orgs are capped at 4 GB. Calls above the cap throw `PlanLimitError`.
+
+---
+
+## `sandbox.scale(opts)`
+
+Manually resize the sandbox. [HTTP API →](/api-reference/sandboxes/scale)
+
+<ParamField body="memoryMB" type="number" required>
+ Target memory in MB.
+</ParamField>
+
+**Returns:** `Promise<{ sandboxID: string; memoryMB: number; cpuPercent: number }>`
+
+**Throws:**
+
+- `ScalingLockedError` — sandbox has a scaling lock active.
+- `PlanLimitError` — `memoryMB` exceeds the org's plan cap.
+
+```typescript
+import { 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)`
+
+Enable or disable per-sandbox autoscale.
+
+<ParamField body="enabled" type="boolean" required>
+ Whether autoscale should be active.
+</ParamField>
+
+<ParamField body="minMemoryMB" type="number">
+ Lower bound when `enabled=true`.
+</ParamField>
+
+<ParamField body="maxMemoryMB" type="number">
+ Upper bound when `enabled=true`. Must be ≥ `minMemoryMB`.
+</ParamField>
+
+**Returns:** `Promise<{ sandboxID: string; enabled: boolean; minMemoryMB: number; maxMemoryMB: number }>`
+
+**Throws:**
+
+- `ScalingLockedError` — sandbox has a scaling lock active.
+- `PlanLimitError` — `maxMemoryMB` exceeds the org's plan cap.
+
+When `enabled=true`, the platform watches the sandbox's memory pressure and resizes it within the bounds:
+
+- **Scale up** on a single 1-min sample above 75% memory utilization. Cooldown 60s between up-scales.
+- **Scale down** only when 1-min, 5-min, AND 15-min averages all sit below 25%. Cooldown 5 min between down-scales.
+
+The asymmetry matches user perception: rapid response when the user notices lag, conservative shrink after sustained idle. The 15-min window is the dominant constraint on shrink, so a sandbox that briefly idles and resumes won't sawtooth.
+
+```typescript
+await sandbox.setAutoscale({
+ enabled: true,
+ minMemoryMB: 1024,
+ maxMemoryMB: 16384,
+});
+```
+
+To turn off:
+
+```typescript
+await sandbox.setAutoscale({ enabled: false });
+```
+
+---
+
+## `sandbox.getAutoscale()`
+
+Get the current autoscale configuration.
+
+**Returns:** `Promise<{ sandboxID: string; enabled: boolean; minMemoryMB: number; maxMemoryMB: number }>`
+
+```typescript
+const cfg = await sandbox.getAutoscale();
+if (cfg.enabled) {
+ console.log(`autoscale ${cfg.minMemoryMB}–${cfg.maxMemoryMB} MB`);
+}
+```
+
+---
+
+## `sandbox.setScalingLock(locked)`
+
+Lock or unlock the sandbox's resources against any size change.
+
+<ParamField body="locked" type="boolean" required>
+ `true` to freeze, `false` to allow scaling again.
+</ParamField>
+
+**Returns:** `Promise<{ sandboxID: string; locked: boolean }>`
+
+While locked:
+
+- `scale()` rejects with `ScalingLockedError`.
+- `setAutoscale({ enabled: true })` rejects with `ScalingLockedError`.
+- The platform autoscaler skips this sandbox entirely.
+
+Locking ALSO disables autoscale (single knob — "I don't want this scaling"). Unlocking does **not** re-enable autoscale; call `setAutoscale({ enabled: true, ... })` explicitly if you want it back.
+
+```typescript
+// 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()`
+
+Get the current scaling-lock state.
+
+**Returns:** `Promise<{ sandboxID: string; locked: boolean }>`
+
+---
+
+## Errors
+
+### `ScalingLockedError`
+
+Thrown when the sandbox has a scaling lock active. Has a `code` property of `"scaling_locked"` for parity with the HTTP API's error code.
+
+```typescript
+import { ScalingLockedError } from "@opencomputer/sdk";
+
+try {
+ await sandbox.scale({ memoryMB: 8192 });
+} catch (err) {
+ if (err instanceof ScalingLockedError) {
+ // unlock first, or surface to user
+ }
+}
+```
+
+### `PlanLimitError`
+
+Thrown when the requested size exceeds the org's plan cap. The HTTP API returns 402 Payment Required for this case.
diff --git a/docs/sandboxes/burst-sandboxes.mdx b/docs/sandboxes/burst-sandboxes.mdx
index 2ddd8fa3..bf673033 100644
--- a/docs/sandboxes/burst-sandboxes.mdx
+++ b/docs/sandboxes/burst-sandboxes.mdx
@@ -225,8 +225,8 @@ When OpenComputer receives notice, it runs the hook with the notice window in se
## Related
<CardGroup cols={2}>
- <Card title="Sizing" href="/sandboxes/sizing">
- Resource tiers and how to choose one
+ <Card title="Elasticity" href="/sandboxes/elasticity">
+ Resource tiers and autoscaling
</Card>
<Card title="Checkpoints" href="/sandboxes/checkpoints">
Save and resume sandbox state
diff --git a/docs/sandboxes/elasticity.mdx b/docs/sandboxes/elasticity.mdx
new file mode 100644
index 00000000..5a1333c5
--- /dev/null
+++ b/docs/sandboxes/elasticity.mdx
@@ -0,0 +1,307 @@
+---
+title: "Elasticity"
+description: "Dynamically scale sandbox memory and CPU — automatically, manually, or via the in-VM API"
+---
+
+A sandbox's memory and CPU can be resized at runtime. The platform's recommended path is **Autoscaling** — opt the sandbox in once and we resize it for you based on observed memory pressure. Lower-level controls are also available if you want to drive sizing yourself or freeze it.
+
+CPU scales proportionally to memory in all modes (1 vCPU per ~4 GB up to 16 GB / 4 vCPU). The permissible memory tiers are:
+
+| Memory | vCPU |
+| --- | --- |
+| 1 GB | 1 (best-effort) |
+| 4 GB | 1 |
+| 8 GB | 2 |
+| 16 GB | 4 |
+
+If you want a sandbox to **stay at a fixed size**, see [Locking Resources](#locking-resources).
+
+## Autoscaling
+
+Opt a sandbox into the per-sandbox autoscaler and the platform resizes it for you based on observed memory pressure. Autoscale is **opt-in per sandbox** and **disabled by default**.
+
+This is the recommended way to size a sandbox: turn it on once with bounds you're comfortable with, then leave it. Manual `scale` and the in-VM API are escape hatches for cases where the autoscaler isn't a good fit (e.g. you want a hard guarantee for a benchmark, or you're scripting your own logic).
+
+### Enable
+
+<CodeGroup>
+```typescript TypeScript
+await sandbox.setAutoscale({
+ enabled: true,
+ minMemoryMB: 1024,
+ maxMemoryMB: 16384,
+});
+```
+
+```python Python
+await sandbox.set_autoscale(
+ enabled=True,
+ min_memory_mb=1024,
+ max_memory_mb=16384,
+)
+```
+
+```bash CLI
+oc sandbox autoscale sb-abc123 --on --min 1024 --max 16384
+```
+
+```bash HTTP
+curl -sf -X PUT "$API/api/sandboxes/$SANDBOX_ID/autoscale" \
+ -H "X-API-Key: $API_KEY" \
+ -H "Content-Type: application/json" \
+ -d '{"enabled": true, "minMemoryMB": 1024, "maxMemoryMB": 16384}'
+```
+</CodeGroup>
+
+`minMemoryMB` and `maxMemoryMB` must be values from the tier table above. The autoscaler keeps the sandbox between these bounds, in tier steps.
+
+### Behavior
+
+- **Scale up**: when the sandbox's 1-minute average memory utilization exceeds 75 %, jump to the next tier. 60-second cooldown between up-events.
+- **Scale down**: when **all** of the 1-min, 5-min, and 15-min utilization averages stay below 25 %, drop one tier. 5-minute cooldown between down-events. Down requires at least 15 minutes of low-utilization data, so a brief idle pause won't shrink you.
+- **Manual override**: any explicit `scale` call disables autoscale on that sandbox. Re-enable explicitly via `setAutoscale({ enabled: true, ... })` (or the equivalent in any SDK) if you want it back.
+
+### Disable
+
+<CodeGroup>
+```typescript TypeScript
+await sandbox.setAutoscale({ enabled: false });
+```
+
+```python Python
+await sandbox.set_autoscale(enabled=False)
+```
+
+```bash CLI
+oc sandbox autoscale sb-abc123 --off
+```
+
+```bash HTTP
+curl -sf -X PUT "$API/api/sandboxes/$SANDBOX_ID/autoscale" \
+ -H "X-API-Key: $API_KEY" \
+ -d '{"enabled": false}'
+```
+</CodeGroup>
+
+### Inspect
+
+<CodeGroup>
+```typescript TypeScript
+const cfg = await sandbox.getAutoscale();
+// { sandboxID: "sb-...", enabled: true, minMemoryMB: 1024, maxMemoryMB: 16384 }
+```
+
+```python Python
+cfg = await sandbox.get_autoscale()
+# {"sandboxID": "sb-...", "enabled": True, "minMemoryMB": 1024, "maxMemoryMB": 16384}
+```
+
+```bash CLI
+oc sandbox autoscale sb-abc123
+# Autoscale enabled for sb-abc123 (1024–16384 MB)
+```
+
+```bash HTTP
+curl -sf "$API/api/sandboxes/$SANDBOX_ID/autoscale" -H "X-API-Key: $API_KEY"
+# {"sandboxID":"sb-...","enabled":true,"minMemoryMB":1024,"maxMemoryMB":16384}
+```
+</CodeGroup>
+
+## Manual Scaling (Control Plane)
+
+When you want to resize once — predictable size for a benchmark, a one-off scale-up before a known-heavy task, an operator response to an alert — call `scale` from your application or operator tooling:
+
+<CodeGroup>
+```typescript TypeScript
+await sandbox.scale({ memoryMB: 4096 });
+```
+
+```python Python
+await sandbox.scale(memory_mb=4096)
+```
+
+```bash CLI
+oc sandbox scale sb-abc123 4096
+```
+
+```bash HTTP
+curl -sf -X POST "$API/api/sandboxes/$SANDBOX_ID/scale" \
+ -H "X-API-Key: $API_KEY" \
+ -H "Content-Type: application/json" \
+ -d '{"memoryMB": 4096}'
+```
+</CodeGroup>
+
+A manual scale **disables autoscale** on the sandbox — explicit user intent overrides the loop. Re-enable it later if you want size to track load again.
+
+The endpoint can return:
+
+- **403 `scaling_locked`** — the sandbox is locked. See [Locking Resources](#locking-resources).
+- **409 `oom_floor`** — the requested size would force a guest OOM-kill because the current working set exceeds it. Free memory inside the guest, then retry.
+- **402 Payment Required** — the requested size exceeds your plan cap.
+
+## In-VM Scaling
+
+Sandboxes expose an internal metadata API at `http://169.254.169.254` that lets code **inside** the VM scale itself. Useful for workload-aware scripts where the workload knows its own demand better than the platform autoscaler can infer (e.g. "scale up before this build, back down after").
+
+<Note>
+ This endpoint is only reachable from inside the sandbox. It is not exposed through the control plane API or SDKs.
+</Note>
+
+### Scale Memory
+
+Send a `POST` to `/v1/scale` with the desired memory in MB. CPU is adjusted proportionally.
+
+```bash
+curl -s -X POST http://169.254.169.254/v1/scale \
+ -H "Content-Type: application/json" \
+ -d '{"memoryMB": 4096}'
+```
+
+### Check Current Limits
+
+```bash
+curl -s http://169.254.169.254/v1/limits
+```
+
+### Example: Rust Compilation
+
+Rust builds are memory-hungry. You can alias `cargo` to scale up before compilation and scale back down after:
+
+```bash
+alias cargo='_cargo_scaled'
+_cargo_scaled() {
+ # Scale up to 16GB / 4 vCPU before build
+ curl -sf -X POST http://169.254.169.254/v1/scale \
+ -H "Content-Type: application/json" -d '{"memoryMB": 16384}'
+
+ # Run the actual cargo command
+ command cargo "$@"
+ local exit_code=$?
+
+ # Scale back down to 4GB / 1 vCPU
+ curl -sf -X POST http://169.254.169.254/v1/scale \
+ -H "Content-Type: application/json" -d '{"memoryMB": 4096}'
+
+ return $exit_code
+}
+```
+
+Add this to your sandbox's `~/.bashrc` or inject it via `sandbox.exec.run` so every `cargo build`, `cargo test`, etc. automatically gets the extra resources.
+
+### Example: Custom Scaling Loop
+
+A simple shell script that monitors memory pressure and scales automatically. Useful when you want fine-grained control inside the sandbox itself; for the platform-managed equivalent see [Autoscaling](#autoscaling) above.
+
+```bash
+#!/bin/sh
+SCALE_API="http://169.254.169.254/v1/scale"
+MIN_MB=1024
+MAX_MB=8192
+SCALE_UP_THRESHOLD=80
+SCALE_DOWN_THRESHOLD=30
+COOLDOWN=30
+last_scale=0
+
+while true; do
+ mem_total=$(awk '/MemTotal/{print $2}' /proc/meminfo)
+ mem_avail=$(awk '/MemAvailable/{print $2}' /proc/meminfo)
+ usage_pct=$(( (mem_total - mem_avail) * 100 / mem_total ))
+ total_mb=$((mem_total / 1024))
+ now=$(date +%s)
+ elapsed=$((now - last_scale))
+
+ if [ $usage_pct -gt $SCALE_UP_THRESHOLD ] && [ $elapsed -gt $COOLDOWN ]; then
+ new_mb=$((total_mb * 2))
+ [ $new_mb -gt $MAX_MB ] && new_mb=$MAX_MB
+ if [ $new_mb -gt $total_mb ]; then
+ echo "usage=$usage_pct% -> scaling UP to ${new_mb}MB"
+ curl -sf -X POST "$SCALE_API" \
+ -H "Content-Type: application/json" \
+ -d "{\"memoryMB\":$new_mb}"
+ last_scale=$now
+ fi
+ elif [ $usage_pct -lt $SCALE_DOWN_THRESHOLD ] && [ $total_mb -gt $MIN_MB ] && [ $elapsed -gt $COOLDOWN ]; then
+ new_mb=$((total_mb / 2))
+ [ $new_mb -lt $MIN_MB ] && new_mb=$MIN_MB
+ if [ $new_mb -lt $total_mb ]; then
+ echo "usage=$usage_pct% -> scaling DOWN to ${new_mb}MB"
+ curl -sf -X POST "$SCALE_API" \
+ -H "Content-Type: application/json" \
+ -d "{\"memoryMB\":$new_mb}"
+ last_scale=$now
+ fi
+ fi
+
+ sleep 5
+done
+```
+
+## Locking Resources
+
+If you want a sandbox to **stay at a fixed size** — predictable billing, a benchmark, a long-running pinned workload — lock it. Locking blocks both manual scaling and autoscaling on the sandbox.
+
+<CodeGroup>
+```typescript TypeScript
+await sandbox.setScalingLock(true);
+```
+
+```python Python
+await sandbox.set_scaling_lock(True)
+```
+
+```bash CLI
+oc sandbox lock sb-abc123
+```
+
+```bash HTTP
+curl -sf -X PUT "$API/api/sandboxes/$SANDBOX_ID/scaling-lock" \
+ -H "X-API-Key: $API_KEY" \
+ -H "Content-Type: application/json" \
+ -d '{"locked": true}'
+```
+</CodeGroup>
+
+While locked:
+
+- `scale` returns **403** `scaling_locked`
+- `setAutoscale({ enabled: true })` returns **403** `scaling_locked`
+- The autoscaler skips the sandbox
+
+Locking automatically disables autoscale on the sandbox, so you have a single user-facing toggle. Unlocking does **not** auto-re-enable autoscale; turn it back on explicitly if you want it.
+
+<CodeGroup>
+```typescript TypeScript
+// Unlock
+await sandbox.setScalingLock(false);
+
+// Inspect
+const lock = await sandbox.getScalingLock();
+// { sandboxID: "sb-...", locked: false }
+```
+
+```python Python
+# Unlock
+await sandbox.set_scaling_lock(False)
+
+# Inspect
+lock = await sandbox.get_scaling_lock()
+# {"sandboxID": "sb-...", "locked": False}
+```
+
+```bash CLI
+oc sandbox unlock sb-abc123
+oc sandbox lock-status sb-abc123
+```
+
+```bash HTTP
+# Unlock
+curl -sf -X PUT "$API/api/sandboxes/$SANDBOX_ID/scaling-lock" \
+ -H "X-API-Key: $API_KEY" \
+ -d '{"locked": false}'
+
+# Inspect
+curl -sf "$API/api/sandboxes/$SANDBOX_ID/scaling-lock" -H "X-API-Key: $API_KEY"
+# {"sandboxID":"sb-...","locked":false}
+```
+</CodeGroup>
diff --git a/docs/sandboxes/sizing.mdx b/docs/sandboxes/sizing.mdx
deleted file mode 100644
index 25bee7f5..00000000
--- a/docs/sandboxes/sizing.mdx
+++ /dev/null
@@ -1,66 +0,0 @@
----
-title: "Sizing"
-description: "Choose a sandbox's memory and CPU at create time"
----
-
-A sandbox's memory is chosen when you create it and stays fixed for the
-sandbox's lifetime. CPU is allocated proportionally to memory.
-
-| Memory | vCPU |
-| --- | --- |
-| 1 GB | best-effort |
-| 4 GB (default) | 1 |
-| 8 GB | 2 |
-
-Omitting `memoryMB` gives you the 4 GB default.
-
-## Choosing a size
-
-Pass `memoryMB` at create:
-
-<CodeGroup>
-```typescript TypeScript
-const sandbox = await Sandbox.create({ memoryMB: 8192 });
-```
-
-```bash CLI
-oc sandbox create --memory 8192
-```
-
-```bash HTTP
-curl -sf -X POST "$API/api/sandboxes" \
- -H "X-API-Key: $API_KEY" \
- -H "Content-Type: application/json" \
- -d '{"memoryMB": 8192}'
-```
-</CodeGroup>
-
-`cpuCount` may be given instead and the matching memory tier is inferred. If both
-are supplied they must describe the same tier.
-
-<Note>
- The 1 GB tier provides CPU on a best-effort basis. For CPU-sensitive work, use
- 4 GB or above.
-</Note>
-
-## Sizes outside the table
-
-A request for a size that is not offered is **rejected**, not rounded down. You
-will never be quietly given a smaller sandbox than you asked for, and never
-billed for a size you did not receive.
-
-Sizes above 8 GB are not available self-serve. If you need more, contact us —
-larger configurations are handled out of band.
-
-## Size is fixed for the sandbox's lifetime
-
-Memory cannot be changed after a sandbox starts. Size is a property of the
-machine the sandbox runs on, decided when that machine boots, so there is no
-resize operation to call.
-
-If a workload needs more memory than it was created with, create a new sandbox
-at the larger tier. Where you need to carry work across, write what matters to
-the workspace and read it back on the new sandbox.
-
-Plan for the peak rather than the average: a sandbox that occasionally needs
-8 GB should be created at 8 GB.