|
| 1 | +--- |
| 2 | +title: "Patches" |
| 3 | +description: "Rolling updates for forked sandboxes" |
| 4 | +--- |
| 5 | + |
| 6 | +Patches attach bash scripts to a checkpoint. When a sandbox boots from that checkpoint or wakes from hibernation, all pending patches run automatically in sequence order. |
| 7 | + |
| 8 | +## Create a Patch |
| 9 | + |
| 10 | +```typescript |
| 11 | +const result = await Sandbox.createCheckpointPatch(checkpoint.id, { |
| 12 | + script: "npm install lodash@4.17.21", |
| 13 | + description: "Pin lodash version", |
| 14 | +}); |
| 15 | + |
| 16 | +console.log(result.patch.sequence); // 1 |
| 17 | +``` |
| 18 | + |
| 19 | +### `Sandbox.createCheckpointPatch(checkpointId, opts)` |
| 20 | + |
| 21 | +<ParamField body="checkpointId" type="string" required> |
| 22 | + UUID of the checkpoint to patch. |
| 23 | +</ParamField> |
| 24 | +<ParamField body="opts" type="object" required> |
| 25 | + <Expandable title="properties"> |
| 26 | + <ParamField body="script" type="string" required> |
| 27 | + Bash script to execute inside the sandbox. |
| 28 | + </ParamField> |
| 29 | + <ParamField body="description" type="string" optional> |
| 30 | + Human-readable description. |
| 31 | + </ParamField> |
| 32 | + <ParamField body="apiKey" type="string" optional> |
| 33 | + API key override. |
| 34 | + </ParamField> |
| 35 | + <ParamField body="apiUrl" type="string" optional> |
| 36 | + API URL override. |
| 37 | + </ParamField> |
| 38 | + </Expandable> |
| 39 | +</ParamField> |
| 40 | + |
| 41 | +**Returns:** `Promise<PatchResult>` |
| 42 | + |
| 43 | +## List Patches |
| 44 | + |
| 45 | +```typescript |
| 46 | +const patches = await Sandbox.listCheckpointPatches(checkpoint.id); |
| 47 | +// [{ id: "...", sequence: 1, script: "...", description: "..." }, ...] |
| 48 | +``` |
| 49 | + |
| 50 | +### `Sandbox.listCheckpointPatches(checkpointId, opts?)` |
| 51 | + |
| 52 | +**Returns:** `Promise<PatchInfo[]>` — ordered by sequence number. |
| 53 | + |
| 54 | +## Delete a Patch |
| 55 | + |
| 56 | +Remove a bad or unwanted patch. Remaining patches continue to apply in sequence order. |
| 57 | + |
| 58 | +```typescript |
| 59 | +await Sandbox.deleteCheckpointPatch(checkpoint.id, patch.id); |
| 60 | +``` |
| 61 | + |
| 62 | +### `Sandbox.deleteCheckpointPatch(checkpointId, patchId, opts?)` |
| 63 | + |
| 64 | +<ParamField body="checkpointId" type="string" required> |
| 65 | + UUID of the checkpoint. |
| 66 | +</ParamField> |
| 67 | +<ParamField body="patchId" type="string" required> |
| 68 | + UUID of the patch to delete. |
| 69 | +</ParamField> |
| 70 | + |
| 71 | +**Returns:** `Promise<void>` |
| 72 | + |
| 73 | +## How Patches Apply |
| 74 | + |
| 75 | +| Event | Patches run? | |
| 76 | +| --- | --- | |
| 77 | +| `Sandbox.createFromCheckpoint()` | Yes — after boot | |
| 78 | +| `sandbox.wake()` | Yes — after restore | |
| 79 | +| Sandbox already running | No — next wake/boot | |
| 80 | + |
| 81 | +Patches run sequentially by sequence number. If a patch fails (non-zero exit), the chain stops. Progress is tracked per-sandbox, so the next wake retries from the last successful patch. |
0 commit comments