Skip to content

feat: add uf sandbox command for containerized OpenCode sessions #91

Closed

Description

@jflowers

Context

The containerized OpenCode environment is ready — containerfile#1 delivered the Containerfile, devfiles, podman-compose, and scripts. The missing piece is a uf sandbox CLI command that orchestrates the multi-step Podman workflow into a single command.

Part of: Discussion #88
Depends on: containerfile#1 (closed, complete)

Proposed Command

uf sandbox start              # start container + attach TUI
uf sandbox start --detach     # start container, print URL
uf sandbox attach             # attach to running container
uf sandbox stop               # stop and remove container
uf sandbox extract            # git format-patch from container to host

What uf sandbox start Does

  1. Check prerequisites: Podman installed (LookPath), Ollama running (probe localhost:11434), API keys in environment
  2. Detect platform: arm64/amd64 (runtime.GOARCH), SELinux presence (:Z flag on Fedora)
  3. Resolve image: Default quay.io/unbound-force/opencode-dev:latest, overridable via --image flag or UF_SANDBOX_IMAGE env var
  4. Pull if needed: podman pull <image>
  5. Start container: podman run -d with correct volume mounts, env vars, resource limits, port mapping
  6. Wait for ready: Poll http://localhost:4096/health until healthy (timeout 60s)
  7. Attach: Run opencode attach http://localhost:4096 (or return URL if --detach)

What uf sandbox extract Does

  1. Check container is running (podman ps)
  2. Run git format-patch inside container
  3. Present patch for human review (summary of changes)
  4. Apply on confirmation (git am)

Modes

  • --mode isolated (default): Read-only source mount. Agent works on a copy. Changes extracted via git format-patch. Maximum safety.
  • --mode direct: Read-write volume mount. Agent writes directly to host. Convenience for trusted tasks.

Configurable via UF_SANDBOX_MODE=isolated|direct or CLI flag.

Design Decisions

  • Single container only: One uf-sandbox container at a time. No concurrent container support (simplifies naming, ports, mental model).
  • Podman as prerequisite: uf doctor can check if Podman is installed but uf setup does NOT install it (platform-specific, typically handled by OS).
  • Ollama on host: Container connects via DEWEY_EMBEDDING_ENDPOINT=http://host.containers.internal:11434. Keeps the image light.
  • Resource limits: Default --memory 8g --cpus 4, overridable via --memory and --cpus flags.

New Package

internal/sandbox/
\u251c\u2500\u2500 sandbox.go         # Core logic (start, stop, attach, extract)
\u251c\u2500\u2500 detect.go          # Platform detection (arch, SELinux, Podman version)
\u251c\u2500\u2500 config.go          # Container config (image, volumes, env, limits)
\u2514\u2500\u2500 sandbox_test.go    # Tests with mock exec

Plus Cobra command wiring in cmd/unbound-force/.

Estimated Scope

  • ~300 lines Go code (internal/sandbox/)
  • ~100 lines Cobra commands
  • ~400 lines tests
  • ~20 lines AGENTS.md
  • Speckit strategic spec (028)

Platforms

  • macOS arm64 (MacBook Pro)
  • Fedora amd64 (workstation/server)
  • SELinux-aware volume mounting (:Z flag detection)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions