@@ -174,3 +174,72 @@ Because this template extends the `claude-code` base image, you run it with
174174Template images are cached locally. The first use pulls from the registry;
175175subsequent sandboxes reuse the cache. Cached images persist across sandbox
176176creation 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+ ```
0 commit comments