@@ -22,7 +22,7 @@ Use custom templates when:
2222For one-off work or simple setups, use the default template and ask the agent
2323to install what's needed.
2424
25- ## Building a template
25+ ## Building templates with Dockerfiles
2626
2727Start from Docker's official sandbox templates:
2828
@@ -46,9 +46,9 @@ RUN pip3 install --no-cache-dir \
4646USER agent
4747```
4848
49- Official templates include the agent binary, Ubuntu base, development tools
50- ( Git, Docker CLI, Node.js, Python, Go), and the non-root ` agent ` user with
51- sudo access.
49+ Official templates include the agent binary, Ubuntu base, and development tools
50+ like Git, Docker CLI, Node.js, Python, and Go. They run as the non-root
51+ ` agent ` user with sudo access.
5252
5353### The USER pattern
5454
@@ -57,42 +57,74 @@ end. The base template defaults to `USER agent`, so you need to explicitly
5757switch to root for package installations. Always switch back to ` agent ` before
5858the end of your Dockerfile so the agent runs with the correct permissions.
5959
60- ### Using templates
60+ ### Using templates built from Dockerfiles
6161
6262Build your template:
6363
6464``` console
6565$ docker build -t my-template:v1 .
6666```
6767
68- Then choose how to use it:
69-
70- Option 1: Load from local images (quick, for personal use)
68+ Use it directly from your local Docker daemon:
7169
7270``` console
73- $ docker sandbox create --template my-template:v1 \
74- --load-local-template \
75- claude ~/project
76- $ docker sandbox run < sandbox-name>
71+ $ docker sandbox run --load-local-template -t my-template:v1 claude ~ /project
7772```
7873
79- The ` --load-local-template ` flag loads the image from your local Docker daemon
80- into the sandbox VM. This works for quick iteration and personal templates .
74+ The ` --load-local-template ` flag tells the sandbox to use an image from your
75+ local Docker daemon. Without it, the sandbox looks for the image in a registry .
8176
82- Option 2: Push to a registry (for sharing and persistence)
77+ To share the template with others, push it to a registry:
8378
8479``` console
8580$ docker tag my-template:v1 myorg/my-template:v1
8681$ docker push myorg/my-template:v1
87- $ docker sandbox create --template myorg/my-template:v1 claude ~ /project
88- $ docker sandbox run < sandbox-name>
82+ $ docker sandbox run -t myorg/my-template:v1 claude ~ /project
8983```
9084
91- Pushing to a registry makes templates available to your team and persists them
92- beyond your local machine.
85+ Once pushed to a registry, you don't need ` --load-local-template ` .
86+
87+ ## Creating templates from existing sandboxes
88+
89+ Rather than writing a Dockerfile, you can start with a sandbox, configure it,
90+ then save it as a template. This is convenient when you already have a working
91+ environment set up by the agent.
92+
93+ Start a sandbox and have the agent install what you need:
94+
95+ ``` console
96+ $ docker sandbox run claude ~ /project
97+ ```
98+
99+ Inside the sandbox, ask the agent to install tools and configure the
100+ environment. Once everything works, exit and save the sandbox as a template:
101+
102+ ``` console
103+ $ docker sandbox save claude-sandbox-2026-02-02-123456 my-template:v1
104+ ✓ Saved sandbox as my-template:v1
105+ ```
106+
107+ This saves the image to your local Docker daemon. Use ` --load-local-template `
108+ to create new sandboxes from it:
109+
110+ ``` console
111+ $ docker sandbox run --load-local-template -t my-template:v1 claude ~ /other-project
112+ ```
113+
114+ To save as a tar file instead (for example, to transfer to another machine):
115+
116+ ``` console
117+ $ docker sandbox save -o template.tar claude-sandbox-2026-02-02-123456 my-template:v1
118+ ```
119+
120+ Use a Dockerfile when you want a clear record of how the environment is built.
121+ Use ` docker sandbox save ` when you already have a working sandbox and want to
122+ reuse it.
93123
94124## Example: Node.js template
95125
126+ This template adds Node.js 20 and common development tools:
127+
96128``` dockerfile
97129FROM docker/sandbox-templates:claude-code
98130
@@ -108,14 +140,14 @@ RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \
108140
109141# Install common tools
110142RUN npm install -g \
111- typescript@5.1.6 \
112- eslint@8.46 .0 \
113- prettier@3.0.0
143+ typescript@5.7.2 \
144+ eslint@9.17 .0 \
145+ prettier@3.4.2
114146
115147USER agent
116148```
117149
118- Pin versions for reproducible builds.
150+ Pin specific versions for reproducible builds across your team .
119151
120152## Using standard images
121153
@@ -138,21 +170,28 @@ dependencies, configure the shell, and set up the `agent` user. Building from
138170
139171## Sharing with teams
140172
141- Push templates to a registry and version them :
173+ To share templates, push them to a registry with version tags :
142174
143175``` console
144176$ docker build -t myorg/sandbox-templates:python-v1.0 .
145177$ docker push myorg/sandbox-templates:python-v1.0
146178```
147179
148- Team members can then use the template:
180+ Or tag and push a saved sandbox:
181+
182+ ``` console
183+ $ docker tag my-template:v1 myorg/my-template:v1.0
184+ $ docker push myorg/my-template:v1.0
185+ ```
186+
187+ Team members use the template by referencing the registry image:
149188
150189``` console
151- $ docker sandbox create --template myorg/sandbox-templates:python-v1.0 claude ~ /project
190+ $ docker sandbox run -t myorg/sandbox-templates:python-v1.0 claude ~ /project
152191```
153192
154- Using version tags ( ` :v1.0 ` , ` :v2.0 ` ) instead of ` :latest ` ensures stability
155- across your team.
193+ Use version tags like ` :v1.0 ` instead of ` :latest ` for consistency across your
194+ team.
156195
157196## Next steps
158197
0 commit comments