Skip to content

Commit c953aee

Browse files
authored
Merge pull request #24734 from dvdksn/fix/sbx-save-load-docs
docs: add sbx save/load snapshot workflow to custom environments
1 parent f742761 commit c953aee

File tree

8 files changed

+199
-31
lines changed

8 files changed

+199
-31
lines changed

content/manuals/ai/sandboxes/agents/custom-environments.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,3 +174,72 @@ Because this template extends the `claude-code` base image, you run it with
174174
Template images are cached locally. The first use pulls from the registry;
175175
subsequent sandboxes reuse the cache. Cached images persist across sandbox
176176
creation and deletion, and are cleared when you run `sbx reset`.
177+
178+
## Saving a sandbox as a template
179+
180+
Instead of writing a Dockerfile, you can save a running sandbox's state as a
181+
template. This captures installed packages, configuration changes, and files
182+
into a reusable image — useful when you've set up an environment interactively
183+
and want to preserve it.
184+
185+
### Save and reuse
186+
187+
Stop the sandbox (or let the CLI prompt you), then save it with a name and
188+
tag:
189+
190+
```console
191+
$ sbx template save my-sandbox my-template:v1
192+
```
193+
194+
The image is stored in the sandbox runtime's local image store. Create a new
195+
sandbox from it with the `-t` flag:
196+
197+
```console
198+
$ sbx run -t my-template:v1 claude
199+
```
200+
201+
### List and remove templates
202+
203+
List all saved templates:
204+
205+
```console
206+
$ sbx template ls
207+
```
208+
209+
Remove a template you no longer need:
210+
211+
```console
212+
$ sbx template rm my-template:v1
213+
```
214+
215+
### Export and import
216+
217+
To share a saved template or move it to another machine, export it as a tar
218+
file:
219+
220+
```console
221+
$ sbx template save my-sandbox my-template:v1 --output my-template.tar
222+
```
223+
224+
On the other machine, load the tar file and use it:
225+
226+
```console
227+
$ sbx template load my-template.tar
228+
$ sbx run -t my-template:v1 claude
229+
```
230+
231+
### Limitations
232+
233+
Agent configuration files are always recreated when a sandbox is created.
234+
Changes to user-level agent configuration files, such as
235+
`/home/agent/.claude/settings.json` and `/home/agent/.claude.json`, do not
236+
persist in saved templates.
237+
238+
If the saved template was built for a different agent than the one you
239+
specify in `sbx run`, you get a warning. For example, saving a Claude
240+
sandbox and running it with `codex` produces:
241+
242+
```text
243+
⚠ WARNING: template "my-template:v1" was built for the "claude" agent but you are using "codex".
244+
The sandbox may not work correctly. Consider using: sbx run -t my-template:v1 claude
245+
```

data/sbx_cli/sbx.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ see_also:
2626
- sbx reset - Reset all sandboxes and clean up state
2727
- sbx rm - Remove one or more sandboxes
2828
- sbx run - Run an agent in a sandbox
29-
- sbx save - Save a snapshot of the sandbox as a template
3029
- sbx secret - Manage stored secrets
3130
- sbx stop - Stop one or more sandboxes without removing them
31+
- sbx template - Manage sandbox templates
3232
- sbx version - Show Docker Sandboxes version information

data/sbx_cli/sbx_save.yaml

Lines changed: 0 additions & 30 deletions
This file was deleted.

data/sbx_cli/sbx_template.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: sbx template
2+
synopsis: Manage sandbox templates
3+
description: |-
4+
Manage sandbox templates.
5+
6+
Templates are saved snapshots of sandboxes that can be reused to create new
7+
sandboxes with: sbx run -t TAG AGENT [WORKSPACE]
8+
usage: sbx template COMMAND
9+
options:
10+
- name: help
11+
shorthand: h
12+
default_value: "false"
13+
usage: help for template
14+
inherited_options:
15+
- name: debug
16+
shorthand: D
17+
default_value: "false"
18+
usage: Enable debug logging
19+
see_also:
20+
- sbx - Manage AI coding agent sandboxes.
21+
- sbx template load - Load an image from a tar file into the sandbox runtime
22+
- sbx template ls - List template images
23+
- sbx template rm - Remove a template image
24+
- sbx template save - Save a snapshot of the sandbox as a template
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: sbx template load
2+
synopsis: Load an image from a tar file into the sandbox runtime
3+
description: |-
4+
Load an image from a tar file into the sandbox runtime's image store.
5+
6+
The loaded image can be used as a template for new sandboxes.
7+
Tar files are typically created with: sbx template save SANDBOX TAG --output FILE
8+
usage: sbx template load FILE [flags]
9+
options:
10+
- name: help
11+
shorthand: h
12+
default_value: "false"
13+
usage: help for load
14+
inherited_options:
15+
- name: debug
16+
shorthand: D
17+
default_value: "false"
18+
usage: Enable debug logging
19+
example: |4-
20+
# Load an image from a tar file
21+
sbx template load /tmp/myimage.tar # Linux/macOS
22+
sbx template load C:\Users\me\myimage.tar # Windows
23+
24+
# Use the loaded image as a template
25+
sbx run -t myimage:v1.0 claude
26+
see_also:
27+
- sbx template - Manage sandbox templates

data/sbx_cli/sbx_template_ls.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: sbx template ls
2+
synopsis: List template images
3+
description: |
4+
List all template images stored in the sandbox runtime's image store.
5+
usage: sbx template ls [flags]
6+
options:
7+
- name: help
8+
shorthand: h
9+
default_value: "false"
10+
usage: help for ls
11+
- name: json
12+
default_value: "false"
13+
usage: Output in JSON format
14+
inherited_options:
15+
- name: debug
16+
shorthand: D
17+
default_value: "false"
18+
usage: Enable debug logging
19+
example: |4-
20+
# List all template images
21+
sbx template ls
22+
23+
# Output in JSON format
24+
sbx template ls --json
25+
see_also:
26+
- sbx template - Manage sandbox templates

data/sbx_cli/sbx_template_rm.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: sbx template rm
2+
synopsis: Remove a template image
3+
description: |
4+
Remove a template image from the sandbox runtime's image store.
5+
usage: sbx template rm TAG [flags]
6+
options:
7+
- name: help
8+
shorthand: h
9+
default_value: "false"
10+
usage: help for rm
11+
inherited_options:
12+
- name: debug
13+
shorthand: D
14+
default_value: "false"
15+
usage: Enable debug logging
16+
example: |4-
17+
# Remove a template image
18+
sbx template rm myimage:v1.0
19+
see_also:
20+
- sbx template - Manage sandbox templates
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: sbx template save
2+
synopsis: Save a snapshot of the sandbox as a template
3+
description: |-
4+
Save a snapshot of the sandbox as a template.
5+
6+
The saved image is stored in the sandbox runtime's image store and can be
7+
used as a template for new sandboxes with: sbx run -t TAG AGENT [WORKSPACE]
8+
9+
Use --output to also export the image to a tar file that can be shared
10+
and loaded on another host with: sbx template load FILE
11+
usage: sbx template save SANDBOX TAG [flags]
12+
options:
13+
- name: help
14+
shorthand: h
15+
default_value: "false"
16+
usage: help for save
17+
- name: output
18+
shorthand: o
19+
usage: Also export the image to a tar file
20+
inherited_options:
21+
- name: debug
22+
shorthand: D
23+
default_value: "false"
24+
usage: Enable debug logging
25+
example: |4-
26+
# Save as a template for new sandboxes on this host
27+
sbx template save my-sandbox myimage:v1.0
28+
29+
# Also export to a shareable tar file
30+
sbx template save my-sandbox myimage:v1.0 --output /tmp/myimage.tar
31+
see_also:
32+
- sbx template - Manage sandbox templates

0 commit comments

Comments
 (0)