Skip to content

Add bbox run-image ephemeral one-shot command - #207

Merged
JAORMX merged 2 commits into
mainfrom
feat/205-run-image
Jul 1, 2026
Merged

JAORMX merged 2 commits into
mainfrom
feat/205-run-image

Conversation

@JAORMX

@JAORMX JAORMX commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Summary

Implements #205 — bbox run-image IMAGE [flags] -- CMD, an ephemeral one-shot that boots an arbitrary OCI image in a sandbox VM, runs the command, forwards only explicitly-requested env, and persists nothing. No config-file mutation, no registry persistence.

bbox run-image ghcr.io/me/aider-bbox:latest -- aider --model gpt-5

bbox run-image ghcr.io/me/aider-bbox:latest \
  --name aider --env OPENAI_API_KEY --env 'AIDER_*' \
  --memory 4g --cpus 4 --mcp --mcp-authz-profile safe-tools \
  --egress-profile standard --allow-host api.openai.com:443 -- aider

Builds an in-memory agent.Agent from flags via the existing config.AgentFromOverride path (#200) and runs it through the normal SandboxRunner.

Ephemeral defaults (safer-than-custom)

Feature Default Opt-in
Credential persistence OFF (ephemeral by design)
Settings import OFF (ephemeral by design)
Env forwarding EMPTY --env (repeatable; --env-forward alias)
MCP proxy OFF --mcp (forces mcp.mode=env; inherits safe-tools authz default)
Git token forwarding OFF --git-token
SSH agent forwarding OFF --git-ssh-agent
Egress permissive (with stderr disclosure) --egress-profile standard --allow-host ...

Snapshot isolation, review, egress/MCP tighten-only semantics all still apply. Universal BBOX_* env vars are injected as for any agent.

How it works

  • New cobra subcommand run-image (cmd/bbox/run_image.go). The first positional is the image; everything after -- is the command.
  • Reuses run() by extracting a shared runSandbox(...) tail (cmd/bbox/main.go); run() keeps its front-end, runRunImage() builds the in-memory agent then calls the same tail.
  • The ephemeral agent is registered data-only (nil Plugin) via registry.Add — same seam registerCustomAgents uses — so isCustomAgent/applyCustomAgentAuthzDefault apply the safe-tools MCP authz default. Nothing is written to disk.
  • Name derives from the image repo basename (sanitized) when --name is unset; validated via agent.ValidateName.
  • Pure helpers buildRunImageOverride and deriveAgentName are table-tested; validateMCPFlags extracted to de-duplicate front-end validation.

Minimum image contract

Documented in docs/run-image.md: the image provides the Linux rootfs; the agent command must be on PATH inside the image; /bin/sh and a CA bundle at /etc/ssl/certs are expected; sandbox user UID 1000 / /home/sandbox. bbox-init is embedded by the VM runtime (PID 1), not the image.

Verification

  • task fmt — clean
  • task lint — 0 issues
  • task test (race) — all green, incl. new cmd/bbox tests
  • New tests: deriveAgentName, buildRunImageOverride (defaults/env/mcp/authz/egress/resources/copy-semantics), ValidateCustomAgent accept/reject, cobra arg parsing (IMG -- CMD, missing --, empty command), RunE pre-IO errors (--seed-credentials rejection, invalid image ref with lowercase hint, invalid --name), name-collision guard (built-in + custom + derived), --name wins-over-derivation, --env/--env-forward alias merge, validateMCPFlags, and the cfg.Agents map-detach (no aliasing into global config).

Review-panel driven changes

A spec + standards + domain (security/arch/UX/DevEx/duplication/QA) panel reviewed the diff; this commit applies the cross-confirmed findings: git-token/SSH-agent off-by-default (contradicts the issue's "forwards only explicitly requested env"), --seed-credentials rejected as incompatible, name-collision guard covers custom agents (not just built-ins), dead name param dropped, derived agent name surfaced on stderr, MCP validation de-duplicated, cfg.Agents map-aliasing fixed, image-contract discoverable from --help, image-ref error hints lowercase refs.

Notes / out of scope

  • runSandbox still hard-codes infravm.NewMicroVMRunner (no VMRunner injection). A full Prepare-boundary E2E test isn't reachable without that refactor; RunE-level tests stop at the pre-runSandbox boundary (guard, flag parsing, pure helpers). Left for a follow-up.
  • The OCI-manifest minimum-image-contract verification (Phase 5 follow-up) is documented but not enforced here.

Closes #205.

Implements #205: `bbox run-image IMAGE [flags] -- CMD` boots an
arbitrary OCI image once, without editing config or registering an
agent. Builds an in-memory agent.Agent from flags via the existing
config.AgentFromOverride path (#200) and runs it through the normal
SandboxRunner — no config-file mutation, no registry persistence.

Ephemeral defaults (safer-than-custom): credential persistence off,
settings import off, env forwarding empty, MCP off, git token / SSH
agent forwarding off. Egress defaults to permissive with a stderr
disclosure so the bare example boots; tighten with
--egress-profile/--allow-host. --mcp forces mcp.mode=env and
inherits the safe-tools custom-agent authz default.

Reuses run() by extracting a shared runSandbox(...) tail. The
in-memory agent is registered data-only (nil Plugin) so
isCustomAgent/applyCustomAgentAuthzDefault apply the safe-tools
default. Name derives from the image repo basename when --name is
unset.

docs/run-image.md documents the minimum image contract (shell at
/bin/sh, command on PATH, CA bundle, sandbox user UID 1000) and
the ephemeral defaults.

@jhrozek jhrozek left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two findings from review (one HIGH egress bug, one MEDIUM MCP UX issue). The rest of the PR looks solid — clean runSandbox extraction, DDD boundaries respected, and strong table-driven tests.

Comment thread cmd/bbox/run_image.go Resolved
Comment thread cmd/bbox/run_image.go Resolved
Fold --allow-host into the run-image agent override so the
ValidateCustomAgent gate sees hosts for a non-permissive egress
profile. Previously --allow-host flowed only into RunOpts.AllowHosts
(applied at VM start), so the load-time validation rejected
--egress-profile standard/locked unless --mcp was also set, breaking
the documented example. Hosts are parsed via egress.ParseHostFlag and
filed under override.EgressHosts[profile]; runFlags.allowHosts is
cleared to avoid filing them twice.

Warn when MCP sub-flags (--mcp-authz-profile, --mcp-group, --mcp-port,
--mcp-config, --mcp-session-ttl) are set without --mcp, which is off by
default for run-image. They were silently dropped, misleading the
operator into thinking they tightened tool access.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@JAORMX
JAORMX merged commit 2f5fe02 into main Jul 1, 2026
8 checks passed
@JAORMX
JAORMX deleted the feat/205-run-image branch July 1, 2026 06:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BYO agents: bbox run-image ephemeral one-shot run

2 participants