Exploring Docker Sandboxes in the Cloud
Docker Sandboxes gave us a safe place to run AI coding agents on our own laptops. But a local sandbox still needs local CPU, memory and virtualization support. What if your laptop is busy, low on resources, or you want an agent to keep working after you close the lid?
On September 24, 2026, Docker added cloud sandboxes to the docs. You use the same sbx CLI, add one flag, --cloud, and the sandbox runs on Docker-managed infrastructure instead of your machine.
In this post, we will set up a cloud sandbox, run Claude Code inside it, copy results back, control network access, manage expiration, and move a sandbox between local and cloud.
Note: Cloud sandbox support in the sbx CLI is experimental. Features and behavior may change.
What you need
- The
sbxCLI, version 0.45.0 or later - An active Docker Agentic Platform subscription (cloud compute is pay-as-you-go)
- An Anthropic API key if you want to run Claude Code
How --cloud works
--cloud is a global flag. It sends a supported sbx command to the Cloud Sandboxes API instead of the local sandbox daemon:
sbx --cloud ls
Local and cloud are two separate worlds. A sandbox you see in sbx ls will not show up in sbx --cloud ls. The same is true for templates, secrets, volumes and network policy. Keep this in mind for every step below.
Step 1: Sign in and check access
Sign in with the same Docker account you used for the subscription:
sbx login
Then check the CLI, your sign-in, cloud API connectivity and account access in one go:
sbx --cloud diagnose
This check does not need the local sandbox daemon.
Step 2: Add a cloud credential
Secrets you saved for local sandboxes with sbx secret are not available in the cloud. The cloud has its own secret store. For Claude Code, store your Anthropic API key:
sbx --cloud secret set anthropic
The command prompts you for the key. The key stays in the cloud secret store, outside the sandbox filesystem.
A few other useful secret commands:
# Account-scoped GitHub token (available to all your cloud sandboxes)
sbx --cloud secret set github
# Scope an OpenAI key to one sandbox only (set it before creating that sandbox)
sbx --cloud secret set openai --sandbox cloud-project
# List secrets without showing their values
sbx --cloud secret ls
For an API that is not a built-in service, use a custom secret. The cloud proxy adds the header for you based on the destination host:
sbx --cloud secret set-custom --name project-api \
--host api.example.com --env PROJECT_API_TOKEN
Step 3: Create your first cloud sandbox
Create a sandbox for Claude Code without attaching to it. We also allow access to GitHub, because we want to clone a repo:
sbx --cloud create --name cloud-project --allow-network github.com:443 claude
Cloud sandbox names need at least two characters, must start with a letter or number, and can only use letters, numbers and hyphens. Periods are not allowed in the cloud, and default is reserved.
Pick a size
By default you get 2 CPUs and 4 GiB of memory. You can pick one of these fixed sizes:
| Size | CPUs | Memory |
|---|---|---|
| micro | 1 | 2 GiB |
| small | 2 | 4 GiB |
| medium | 4 | 8 GiB |
| large | 8 | 16 GiB |
| xl | 16 | 32 GiB |
bash
sbx --cloud create --name big-project --cpus 4 --memory 8g claude
If you give only --cpus or only --memory, the CLI picks the matching value for the other one. You can also choose the CPU architecture with --platform linux/amd64 or --platform linux/arm64.
Step 4: Get code into the sandbox
A cloud sandbox has no path back to your machine, so you can’t pass a workspace path. Running sbx --cloud run claude . returns an error.
Instead, clone the code inside the sandbox:
sbx --cloud exec cloud-project git clone \
https://github.com/docker/welcome-to-docker.git /home/agent/workspace/project
Or push local files in with cp. Always use absolute paths on the sandbox side:
sbx --cloud cp ./src cloud-project:/home/agent/workspace/src
cp is a one-time copy. It does not mount or sync the folder.
Step 5: Attach to the agent and let it work
sbx --cloud attach cloud-project
Ask Claude to look at /home/agent/workspace/project and write a short description of the app to /home/agent/workspace/review.md.
When you want to step away, press Ctrl+\ to detach. The agent keeps running in the cloud. Come back any time with the same attach command.
Prefer a single command that creates the sandbox (or reuses it if it already exists) and attaches right away? Use run:
sbx --cloud run claude --name cloud-project
For scripts and CI jobs where there is no interactive terminal, start it detached:
sbx --cloud run --detached claude --name cloud-task
Step 6: Copy results back and clean up
Pull the file the agent wrote down to your machine:
sbx --cloud cp cloud-project:/home/agent/workspace/review.md ./review.md
Run any command inside the sandbox to check things:
sbx --cloud exec cloud-project pwd
When you are done, remove the sandbox. This deletes all files stored only in the sandbox and can’t be undone:
sbx --cloud rm cloud-project
Add --force to skip the confirmation prompt in scripts.
Expiration: the one thing you must not forget
This is the biggest difference from local sandboxes. A cloud sandbox expires after one hour by default. When it expires, the service stops sandboxes that can be resumed and deletes the rest.
Set the time-to-live (TTL) and the timeout action when you create the sandbox:
sbx --cloud create --name cloud-project --ttl 2h --on-timeout stop claude
The --on-timeout options are:
stop: keeps the sandbox so you can start it againrestart: stops and immediately starts it (TTL must be at least 1h)delete: removes the sandbox
Check how much time is left, or extend it:
sbx --cloud ttl cloud-project
sbx --cloud ttl +30m cloud-project
You can’t extend past 24 hours from creation, and --ttl 0 is an error, not a way to turn expiration off.
Stop and resume to save money
Compute is not billed while a sandbox is stopped. Stop it and keep its memory and filesystem:
sbx --cloud stop cloud-project
Resume and reconnect later:
sbx --cloud attach cloud-project
Resuming keeps the same sandbox ID and starts a fresh TTL period.
For a quick throwaway session, --rm removes the sandbox as soon as the agent exits:
sbx --cloud run --rm claude
Lock down network access
Cloud network policy is a separate store with two scopes: your Docker account and individual sandboxes. Local policies are not copied to the cloud.
Start from a strict default for your whole account:
sbx --cloud policy init deny-all
You can also use allow-all or balanced (deny-all plus allow rules for common dev services).
Now allow only what your agent needs:
# Account-wide exception
sbx --cloud policy allow network api.github.com:443
# Only for one sandbox
sbx --cloud policy allow network api.anthropic.com:443 \
--sandbox cloud-project
Deny rules always win over allow rules. Check what is configured, then test and read the decision log:
sbx --cloud policy ls
sbx --cloud policy ls cloud-project
sbx --cloud exec cloud-project curl -I https://api.github.com
sbx --cloud policy log cloud-project
Note that HTTP method and path rules (L7 filtering) and --protocol are not supported in the cloud.
Expose a port
Running a web app inside the sandbox? Publish its port and you get a public HTTPS URL:
sbx --cloud ports cloud-project --publish 8080
List or remove published ports:
sbx --cloud ports cloud-project
sbx --cloud ports cloud-project --unpublish 8080
Treat that URL as public. Add authentication in your service and unpublish the port when you no longer need it.
Move a sandbox between local and cloud
This is my favorite part. Start an agent locally, then push it to the cloud when you need to shut your laptop:
sbx move local-project --to cloud --ttl 2h --on-timeout stop
move works across both backends, so don’t add --cloud here. Bring it back down later:
sbx move cloud-project --to local --name local-copy
Then check both sides:
sbx ls
sbx --cloud ls
A few things to know about move:
- It copies a filesystem snapshot, not running processes or memory.
- The source is not deleted. You end up with two independent sandboxes.
- Host workspace mounts, managed secrets and locally added network rules do not travel. Set them up again on the other side.
- Credentials an agent wrote to files inside the sandbox do travel. Sign out and remove them before moving.
- Local and cloud must use the same CPU architecture.
movedoes not convert betweenlinux/amd64andlinux/arm64. - A cloud-to-local move can need up to 32 GiB of temporary disk space.
Persistent volumes and templates
Need a dependency cache that outlives a sandbox? Cloud volumes (experimental) can help:
sbx --cloud volume create dependency-cache
sbx --cloud create --name cloud-project \
--volume dependency-cache:/workspace/cache --on-timeout delete claude
sbx --cloud exec cloud-project \
sudo chown agent:agent /workspace/cache
The chown step is needed because a new volume’s root is owned by root. Volume-backed sandboxes must use the delete timeout action and can’t be stopped.
Once you have a sandbox set up just right, save it as a template and reuse it:
sbx --cloud template save cloud-project cloud-template
sbx --cloud create --name cloud-copy --template cloud-template
Snapshots include any credentials written to the sandbox filesystem, so clean those up first.
One known limitation
If you run Docker inside a cloud sandbox, docker exec can hit the sandbox VM filesystem instead of the target container. This also affects docker compose exec and healthchecks, so services that depend on condition: service_healthy may stay blocked. A container’s main process started with docker run is fine, so run setup or readiness checks as the main command where you can.
Local vs cloud at a glance
| Local sandbox | Cloud sandbox | |
|---|---|---|
| Compute | Your machine | Docker-managed |
| Workspace | Host paths mounted | No host access; clone or cp |
| Hardware (GPU, USB) | Supported | Not available |
| Ports | Host bindings | Public HTTPS URL |
| Secrets | sbx secret | sbx --cloud secret |
| Lifetime | Until you remove it | TTL + timeout action |
| Billing | No metered compute | Pay-as-you-go |
Wrapping up
Cloud sandboxes keep the same sbx workflow you already know and take your laptop out of the picture. The key habits are simple: set cloud secrets first, clone or copy code in instead of mounting it, pick your TTL and timeout action on purpose, and lock down the network with sbx --cloud policy.
Give it a try and share what you build with the Collabnix community.