EXAMPLE 02
  • services
  • databases
  • networking

Private or shared services

Give each instance its own Redis, and every sandbox one shared Postgres.


The problem

Parallel agents on one database step on each other. Some services should belong to one instance and be free to wreck, others are one shared dev database.

A service without scope is isolated, with one container per instance on a network of its own. scope = "global" makes one container shared by every sandbox that lists it. Both answer to the service’s name.

Let your agent set this up

Config

devsandboxes.toml
[services.postgres]
image = "postgres:16"
scope = "global"                       # one for the whole config root
env = { POSTGRES_PASSWORD = "postgres" }
ports = ["127.0.0.1:5432:5432"]        # optional: reach it from the host

[services.redis]
image = "redis:7"                      # no scope: one per instance

[template.base]
image = "node:22"
services = ["postgres", "redis"]
containerEnv = { DATABASE_URL = "postgres://postgres:postgres@postgres:5432/postgres", REDIS_URL = "redis://redis:6379" }

[sandbox.api]
extends = "base"
folder = "../api"

[sandbox.web]
extends = "base"
folder = "../web"

Try it

TERMINAL
devsandbox run api                     # starts postgres, then api with its own redis
devsandbox run api --name fix-login    # its own redis, the same postgres
devsandbox run web
devsandbox service ls

How it works

  • Isolated services follow their instance through stop, start and rm. Give them no host ports, since a second instance would collide. Use devsandbox port instead.
  • A global service keeps running for the others. devsandbox gc removes it once no instance uses it.
  • devsandbox service rebuild postgres applies config changes and rewires running sandboxes in place. The data lives in the container, so keep a way to re-seed.

Agent instructions

Paste it into Claude Code, Codex or any agent with a shell. It finds your repo and config itself and asks only what it can't tell. Agent skills (opens in a new tab)

Source: site/src/content/examples/services.mdxEdit this page on GitHub(opens in a new tab)

MENU /
View on GitHub