Skip to content

feat(sandbox): native sandboxes with per-machine repository caches - #1202

Closed
crispinhu27 wants to merge 8 commits into
mainfrom
feat/local-sandbox-runner-worktree
Closed

crispinhu27 wants to merge 8 commits into
mainfrom
feat/local-sandbox-runner-worktree

Conversation

@crispinhu27

@crispinhu27 crispinhu27 commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

What changed

Native sandboxes replace local sandboxes and carry only environment variables. The local sandbox type is removed. A native sandbox runs on whichever machine executes the work: a user's execution machine, a cloud runner or the platform host. It uses that machine's own toolchains. Environment install scripts, $PREFIX and install PATH entries are gone. Settings such as JAVA_HOME go into the sandbox's environment variables, and MCP servers are installed the way native sandboxes already installed them. SOPs and conversation workspaces can use Docker or native sandboxes. The default sandbox is generic-docker, and AGENTFLOW_LOCAL_SANDBOX is removed. Sandboxes no longer name an execution machine or per-machine repository paths, so a native sandbox is not tied to one machine.

Native workspaces check repositories out from a per-machine repository cache.

  • Each Runner and the platform host keep one bare cache per repository record, at <workspace root>/.repository-cache/<repository id>.git. It is fetched outside the sandbox under a lock and never garbage-collected.
  • In a native sandbox, an SOP checkout becomes git clone --shared of the refreshed cache, with origin set back to the repository URL. If the cache cannot be used, the checkout falls back to a full clone. Docker sandboxes keep full clones.
  • Opening a native conversation workspace warms the project's caches in the background. The repository list sent to the agent tells it to clone from $LOOPFORGE_REPOSITORY_CACHE first. The cache is read-only inside the sandbox (seatbelt rules, --ro-bind-try under bwrap).
  • Workspace checkpoints copy the borrowed objects in (repack -a -d, then drop alternates), so checkpoints restore on machines without the cache.

Users can prefer a sandbox kind for conversation workspaces. 设置 → AI 助手 gains 「对话工作区 → 倾向的沙箱」 (Docker, native, or left to the agent), stored per user as workspaceDriver. When a conversation has no fixed environment, the agent sees that kind first in its choices and opens it when it names no sandbox. It still switches when only another environment has the toolchain a task needs. The workbench environment picker also lists native sandboxes, grouped by kind.

Docker sandboxes carry their own Dockerfile. A docker sandbox now stores its Dockerfile (content plus build-context files). Separately shared Dockerfile and environment assets no longer exist. In the console, 环境资产 becomes 沙箱管理 without type tabs. The sandbox editor edits the Dockerfile inline for docker and only environment variables for native. Old #dockerfiles/#environments links redirect there.

Scope

  • Platform core / API / runner
  • Public adapter / deployment
  • Classic
  • Portable
  • Shared behavior contract
  • Installer / CLI
  • Documentation only

Compatibility

  • Breaking API:
    • /api/dockerfiles, /api/environments and their assistant and MCP tools are removed.
    • PUT /api/sandboxes takes dockerfile {content, files} in place of dockerfileId. It rejects driver: local and ignores install, runnerId, baseDir and repositoryPaths.
    • bootstrap no longer returns dockerfiles or environments.
    • OpenAPI, docs/api/registry.md and CHANGELOG.md are updated.
  • Migration 040 (040_native_sandbox_inline_assets.sql) runs from the installer and ./start.sh pull via scripts/install-schema-extensions.sh. It:
    • copies each referenced Dockerfile into its sandbox and wraps an unreferenced one as a sandbox of its own;
    • turns local sandboxes into native ones;
    • drops install scripts, Dockerfile/environment references and PATH from native sandbox variables (PATH is not rejected on later saves);
    • moves the built-in SOPs that used local to generic-docker;
    • adds assistant_preferences.workspace_driver (startup AutoMigrate adds it too);
    • drops the dockerfiles and environments tables.
    • It also carries the built-in Dockerfile update from 031. Dockerfile content is copied unchanged, so cached images keep the same key.
  • Rows that were not migrated: a stored local sandbox reads as native. A run frozen with a local sandbox asks to be started again with a native one.
  • Runner: runner 0.12.0 checks out from and warms the repository cache. Older runners keep full clones; the runner protocol is otherwise unchanged.
  • CI:
    • The e2e suite runs SOPs in a native e2e-native sandbox it creates in its own project. The browser job installs bubblewrap for it and pulls the pinned platform image for generic-docker, as a Compose install does.
    • first-run builds this checkout instead of pulling the pinned release whenever the schema scripts differ from that release's tag, because the released image cannot read migration 040.

Validation

Run on macOS (arm64), Go 1.26, Node 22, after squashing and rebasing onto current main (v0.4.1):

go build ./... && go vet ./...     pass
go test ./...                      pass except macOS-only failures that also fail on main (see below)
go test ./web/...                  pass
cd chatbot && npx vitest run       pass (58 files, 485 tests)
bash scripts/build-chatbot.sh      pass
python3 scripts/check-public.py    pass
  • TestLocalWorkspaceGitDiscoveryCannotReachParent, TestHostInsteadOfUsernamePromptThenAskPass and TestProcessSandboxPathsProfilesAndCommands (which assumes Linux) fail the same way on a clean main checkout on this machine.
  • New tests cover:
    • cache path validation, shared clones keeping origin, branch clones, cache refresh and rebuilding a broken cache (gitwork);
    • the cache reaching native drivers only, and checkpoints dissociating shared clones (runtime);
    • SOP checkouts from the cache with a full-clone fallback (engine, runner);
    • the agent's cache guidance in native workspaces (httpapi).
  • Live checks against a local platform with a real model key:
    • Migration 040 was applied to a database holding a local sandbox and a native sandbox with an install script. Both became env-only native sandboxes, and the welcome SOP moved to generic-docker.
    • PUT /api/sandboxes rejects local, and keeps only environment for native.
    • A native conversation workspace on the platform host (seatbelt) warmed both project caches. The agent saw only the sandbox's own variable, and clone --shared from $LOOPFORGE_REPOSITORY_CACHE gave a checkout with origin on the repository URL and alternates pointing at the cache. Writing into the cache was denied.
  • Not run:
    • a native SOP run or a conversation on a 0.12.0 runner (covered by unit tests);
    • bash scripts/scan-secrets.sh: the gitleaks binary is Linux-only;
    • python3 scripts/test-install.py: its Linux/Docker installer cases fail on macOS, as on main.

Safety

  • I did not include credentials, internal endpoints, production data, or organization-specific infrastructure.
  • I preserved user files and unrelated changes.
  • I updated generated Classic host bundles when applicable.
  • I documented third-party content and licensing changes when applicable.

…andboxes

Local sandboxes are now for conversation workspaces only. Each one is bound
to one execution machine and its owner, and opens git worktrees of that
machine's own checkouts (per-repository paths, or a clone under
~/.loopforge/local). Native tools inside the workspace follow Claude Code's
default permission rules for every CLI. SOPs can no longer use local; the
default SOP sandbox is generic-docker and AGENTFLOW_LOCAL_SANDBOX is removed.
Migration 040 moves the built-in SOPs to generic-docker.

A sandbox now carries its own Dockerfile (docker) or install script
(native) instead of referencing separately shared Dockerfile and
environment assets. The 环境资产 page becomes 沙箱管理 without type tabs,
and /api/dockerfiles, /api/environments and their assistant tools are
removed. Migration 041, run by the installer and ./start.sh pull, copies
existing recipes into their sandboxes, wraps unused ones as sandboxes of
their own and drops the old tables. The runner protocol is unchanged.

BREAKING CHANGE: /api/dockerfiles and /api/environments are removed;
PUT /api/sandboxes takes dockerfile and install in place of dockerfileId and
environmentId. Unbound local sandboxes must be re-saved by the machine owner.
…om source

SOPs can no longer use local sandboxes, so the e2e suite defaults to
e2e-native, a native sandbox it creates in its own project. The browser job
installs bubblewrap for it, and the public specs save their SOPs on
generic-docker.

The first-run job installs the pinned release with this checkout's schema
scripts. Migration 041 changes the schema in a way the 0.4.0 image cannot
read, so the job now builds this checkout whenever the schema scripts
differ from the pinned tag.
…sandbox

bwrap mounted its private /tmp after binding the workspace, so a workspace
under the host /tmp was hidden and every command failed to chdir. The
private /tmp now comes first.

Engine, API and runner tests run SOP nodes in the test-native sandbox. On
Linux their t.TempDir fixtures lived under the host /tmp, which the sandbox
hides by design, so those test binaries now keep TMPDIR outside /tmp. The
baseline-align test uses test-native instead of the removed local sandbox.
Shared schedule admission checked a sandbox's Dockerfile and environment as
separate assets. Recipes now live in the sandbox, so the sandbox check
covers them. Test fixtures that still used the removed local sandbox for
SOPs now use test-native, and cloning a generic SOP onto local is refused.
@crispinhu27
crispinhu27 force-pushed the feat/local-sandbox-runner-worktree branch from de22db9 to a6481c9 Compare November 22, 2026 10:08
…andbox

A native sandbox gives every command a private /tmp, so the cloud-path test keeps its marker in the workspace there and in /tmp only for containers.
The welcome SOP now runs in generic-docker. Without AGENTFLOW_ISOLATED_IMAGE the browser job built that image during the acceptance specs and they timed out; it now pulls the image pinned in compose.yaml, as a Compose installation does.
…open

A local workspace now starts empty like Docker and native ones. Each turn's
repository list names the machine's checkout of every repository (localPath),
so repositories added after the workspace opened get worktrees too, and the
agent adds them only when a task needs them instead of cloning into the
workspace. Runner cleanup still prunes the worktrees it removes.
Settings → AI 助手 gains a 对话工作区 preference (workspaceDriver: docker,
native, local or empty). The assistant lists that kind first and opens it
when it names no environment; session pins still win. The workbench
environment picker now lists native sandboxes and usable local sandboxes.
@crispinhu27
crispinhu27 deleted the feat/local-sandbox-runner-worktree branch November 23, 2026 09:20
@crispinhu27 crispinhu27 changed the title feat(sandbox): bind local sandboxes to runners and embed recipes in sandboxes feat(sandbox): native sandboxes with per-machine repository caches Nov 23, 2026
@crispinhu27

Copy link
Copy Markdown
Collaborator Author

Superseded by #1258. After discussion this change was redesigned: local sandboxes are removed, native sandboxes carry only environment variables, and native workspaces clone from a per-machine repository cache. Renaming the branch to feat/native-sandbox-repo-cache closed this PR, so the work continues there.

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.

1 participant