Skip to content

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

Open
crispinhu27 wants to merge 10 commits into
mainfrom
feat/native-sandbox-repo-cache
Open

crispinhu27 wants to merge 10 commits into
mainfrom
feat/native-sandbox-repo-cache

Conversation

@crispinhu27

@crispinhu27 crispinhu27 commented Nov 23, 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. Its isolation options, the 设置 → AI 助手 preference and the workbench picker call the two kinds 「Docker」 and 「系统轻量隔离」 (Lightweight system isolation in English). 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.
  • Manual upgrade migration 041 (041_native_sandbox_inline_assets.sql). For Compose upgrades, stop the old platform with ./start.sh stop platform, back up the database with MySQL still running, then apply migration 041 with ./start.sh migrate-sandboxes before starting the upgraded platform. Apply the SQL directly for external MySQL deployments. Fresh installations seed sandboxes with inline Dockerfiles. Migration 041 performs these changes.
    • Copies referenced Dockerfiles into their sandboxes and gives each unused recipe a sandbox of its own, including when its preferred ID is occupied.
    • Converts local sandboxes to native and removes legacy install scripts, asset references and native PATH overrides.
    • Moves built-in SOPs that used local to generic-docker.
    • Adds assistant_preferences.workspace_driver and carries a saved local preference forward as native.
    • Applies the built-in recipe update from 031 and drops the legacy asset tables. A failed catalog transaction preserves the legacy rows for a retry.
  • 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 uses the previous catalog format.

Validation

After merging main, the assistant preferences tests verified the sandbox choice alongside the approval reviewer settings, including saves from older clients. Docker MySQL 8.4 covered legacy conversion, Dockerfile ID collisions, transaction rollback and repeated migration. The repository cache tests passed with safe.bareRepository=explicit. All 12 catalog API cases passed against a fresh local platform, and the desktop settings navigation case passed three consecutive Chromium runs.

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)
cd webtest && node --test tests/  pass (230 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 and a 0.12.0 runner on macOS, with a real model key:
    • The sandbox migration 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.
    • Native script-node SOPs on the platform host and on the runner checked out shared clones of the cache: origin on the repository URL, a fresh work branch, alternates pointing at the cache, the sandbox variable set and the cache read-only. On the runner the first run built the cache (18s), the next reused it (6s), and after its pack files were deleted the cache was rebuilt and the run still succeeded.
    • A Docker SOP still made a full clone, with no cache variable.
    • Native conversations on both machines: with the preference set to 系统轻量隔离 the agent picked a native sandbox on its own; opening the workspace warmed both project caches; the agent cloned from $LOOPFORGE_REPOSITORY_CACHE, branched and committed; writes to the cache were denied. The checkpoint after each turn copied the borrowed objects in and dropped alternates, and the clone passed git fsck --full with the cache moved away.
    • These runs found that Codex started in the read-only <root>/ws under seatbelt (it also does so on main): the platform sends that path as the app-server thread cwd, which Docker and bwrap map onto the run workspace but seatbelt cannot. Stdin to a seatbelt conversation process now names the run workspace instead (e49cddc5).
  • Not run:
    • 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;
    • a Linux (bwrap) runner.

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.

Supersedes #1202, which was closed when its branch was renamed.

Docker sandboxes embed their Dockerfile and native sandboxes carry only
environment variables; the local sandbox type, Dockerfile and environment
assets and install scripts are removed. Native sandboxes run on any
execution machine with its own toolchains. Each Runner and the platform
host keep a bare cache per repository, refreshed outside the sandbox;
native SOP checkouts and conversation agents clone from it with --shared,
and checkpoints copy the borrowed objects in. 设置 → AI 助手 can prefer a
sandbox kind for conversation workspaces. Migration 040 moves Dockerfiles
into sandboxes, turns local sandboxes into native ones and drops install
scripts and PATH.
The sandbox editor, its list, 设置 → AI 助手 and the workbench picker call
the two kinds Docker and 系统轻量隔离 (Lightweight system isolation in
English). The SOP wizard no longer filters local sandboxes, which now read
as native.
The platform sends <root>/ws as the cwd of Codex app-server threads. Docker
and bwrap map that path onto the run workspace; seatbelt cannot, so a
native conversation on macOS started in a read-only directory and the
agent could not check repositories out. Stdin to a seatbelt conversation
process now names the run workspace instead.
Keep native workspace preferences alongside the approval review settings, including when older clients save other preferences.
Reserve 040 for the approval settings migration. Apply 041 explicitly and roll back sandbox data changes on conflicts instead of silently dropping unused Dockerfiles.
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