devsandbox 0.11.1

Manage devcontainer-style sandboxes on docker, podman, or Apple container — many throwaway instances per repo from one TOML config.
---
/**
 * The "docker's verbs" picture of `/docs/vs-docker`: you ask your agent, it
 * clones repos on your machine and drives devsandbox like docker to bring up
 * sandboxes (each one a stack, the compose-project analogue, all in one
 * workspace's config), their instances and services, and the edges
 * between the sandboxes and the host: tunneled ports, the forwarded ssh-agent,
 * `devsbd notify`, and the brokered credentials. Static, in the
 * landing diagram's visual language (`HowItWorks.astro`): one grid on
 * desktop, stacked on narrow screens.
 */
import {
  Bell,
  Bot,
  Container,
  Database,
  FolderGit2,
  GitBranch,
  KeyRound,
  Layers,
  LockKeyhole,
  Plug,
  UserRound,
} from '@lucide/astro';
import '../styles/stacks-diagram.css';

interface Box {
  name: string;
  /** Sandboxes: the repo checkout, or the worktree branch of a repeat instance. */
  tree?: string;
  worktree?: boolean;
  /** Services: `global` or `isolated`. */
  scope?: string;
}

/** The workspace's one config; every sandbox below is a table in it. */
const CONFIG = '~/work/devsandboxes.toml';

// One group per sandbox: its instances (the first on the checkout, repeats on
// worktrees) and its services, isolated, so one per instance.
const stacks: { name: string; sandboxes: Box[]; services: Box[] }[] = [
  {
    name: 'shop',
    sandboxes: [
      { name: 'shop', tree: '~/code/shop' },
      { name: 'shop-2', tree: 'sandbox/shop-2', worktree: true },
    ],
    services: [{ name: 'postgres', scope: 'per instance' }],
  },
  {
    name: 'billing',
    sandboxes: [
      { name: 'billing', tree: '~/code/billing' },
      { name: 'billing-pr-42', tree: 'fix/invoice-rounding', worktree: true },
    ],
    services: [{ name: 'redis', scope: 'per instance' }],
  },
];

const repos = ['shop', 'billing'];

// Bottom row: what crosses the sandbox boundary. `up` = from the host into
// the sandboxes, else out of them.
const edges = [
  { id: 'ports', icon: Plug, label: 'devsandbox port', title: 'localhost:3000', sub: 'shop:3000 · no -p' },
  { id: 'ssh', icon: KeyRound, label: 'ssh · signing', title: 'ssh-agent', sub: 'keys stay on the host', up: true },
  { id: 'notify', icon: Bell, label: 'devsbd notify', title: 'you', sub: 'Inbox · desktop' },
  {
    id: 'creds',
    icon: LockKeyhole,
    label: 'gh · git push · sentry',
    title: 'credentials',
    sub: 'tokens stay on the host',
    up: true,
  },
];
---

<figure class="sd" data-pagefind-ignore>
  <p class="visually-hidden">
    Diagram: on your machine, you ask your agent to set up an environment. It git clones the shop and billing repos
    into ~/code, then drives devsandbox with run --json and exec on your container runtime. There it brings up two
    sandboxes, each a whole stack, both defined in one config for your work workspace, ~/work/devsandboxes.toml: shop,
    with instance shop on its checkout and shop-2 on its own worktree, and a postgres per instance; and billing, with
    instance billing and a child instance billing-pr-42 on its own worktree of the PR branch fix/invoice-rounding, and a
    redis per instance. Across the
    sandbox boundary: ports tunneled to localhost with devsandbox port, your ssh-agent forwarded in so keys stay on the
    host, devsbd notify reaching you in the dashboard's Inbox and on the desktop, and gh, git push and sentry calls
    brokered by the host, so tokens never live in a sandbox.
  </p>

  <div class="sd-host" aria-hidden="true">
    <div class="sd-host-label"><span>HOST</span> your machine</div>

    <div class="sd-grid">
      <div class="sd-repos">
        <div class="sd-head">
          <span class="sd-icon"><FolderGit2 /></span>
          <span class="sd-name">~/code</span>
        </div>
        <div class="sd-chips">
          {
            repos.map((r) => (
              <span class="sd-chip">
                <FolderGit2 />
                {r}
              </span>
            ))
          }
        </div>
      </div>

      <div class="sd-link sd-link--left sd-link--clone"><span>git clone</span></div>

      <div class="sd-agent">
        <span class="sd-agent-icon"><Bot /></span>
        <span class="sd-node-copy">
          <strong>your agent</strong>
          <span>on the host</span>
        </span>
      </div>

      <div class="sd-ask">
        <div class="sd-link sd-link--left sd-link--you"><span>“set up shop”</span></div>
        <div class="sd-you"><UserRound /> you</div>
      </div>

      <div class="sd-link sd-link--down sd-link--mount"><span>folder · worktree</span></div>
      <div class="sd-link sd-link--down sd-link--run"><span>devsandbox run --json · exec</span></div>

      <div class="sd-runtime">
        <div class="sd-runtime-label">
          <span class="sd-runtime-title">RUNTIME</span>
          <span>docker</span><span>podman</span><span>Apple container</span>
          <span class="sd-config">{CONFIG}</span>
        </div>
        <ul class="sd-stacks">
          {
            stacks.map((s) => (
              <li class="sd-stack">
                <div class="sd-stack-head">
                  <Layers />
                  <strong>{s.name}</strong>
                  <span>[sandbox.{s.name}]</span>
                </div>
                <div class="sd-boxes">
                  {s.sandboxes.map((b) => (
                    <div class="sd-box">
                      <div class="sd-head">
                        <span class="sd-icon">
                          <Container />
                        </span>
                        <span class="sd-name">{b.name}</span>
                      </div>
                      <span class:list={['sd-chip', { 'is-worktree': b.worktree }]}>
                        {b.worktree ? <GitBranch /> : <FolderGit2 />}
                        {b.tree}
                      </span>
                    </div>
                  ))}
                  {s.services.map((b) => (
                    <div class="sd-box sd-service">
                      <div class="sd-head">
                        <span class="sd-icon">
                          <Database />
                        </span>
                        <span class="sd-name">{b.name}</span>
                      </div>
                      <span class="sd-sub">service · {b.scope}</span>
                    </div>
                  ))}
                </div>
              </li>
            ))
          }
        </ul>
      </div>

      {
        edges.map((e) => (
          <div class:list={['sd-link', e.up ? 'sd-link--up' : 'sd-link--down', `sd-link--${e.id}`]}>
            <span>{e.label}</span>
          </div>
        ))
      }
      {
        edges.map((e) => (
          <div class:list={['sd-edge', `sd-edge--${e.id}`]}>
            <span class="sd-edge-icon">
              <e.icon />
            </span>
            <span class="sd-node-copy">
              <strong>{e.title}</strong>
              <span>{e.sub}</span>
            </span>
            <span class="sd-edge-via">
              {e.up ? '↑' : '↓'} {e.label}
            </span>
          </div>
        ))
      }
    </div>
  </div>
</figure>