Skip to content

Keep the code in the sandbox; factory-up git prep; pi telemetry off; python kit without services - #16

Merged
dpaez merged 11 commits into
mainfrom
dp/sandbox-private-code
Nov 20, 2026
Merged

dpaez merged 11 commits into
mainfrom
dp/sandbox-private-code

Conversation

@dpaez

@dpaez dpaez commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Refs #14, #15. Closes #17.

#15: VM-private code

A sandbox created without a path mounts nothing from the host. The repository is cloned into ~/workspace, and the factory's worktrees, environments, caches and database stay on the sandbox's disk.

sbx run --clone was considered and not chosen: it protects the host's Git metadata, but the whole host directory, untracked .env included, stays readable at /run/sandbox/source (docs: Isolation → Clone mode; docker/sbx-releases#260).

  • README: new section "Keep the code in the sandbox". It covers the layout comparison, setup (GitHub token, HTTPS clone, a tarball of FACTORY.json, CONTEXT.md and the files they reference, such as .factory/bin; optional larger Docker volume with DOCKER_SANDBOXES_DOCKER_SIZE), getting work out (pull request, bundle, patch, untracked tarball), stop/start vs sbx rm, and moving an existing host-mounted sandbox.
  • factory-up / factory-autostart: factory-up records each repository in ~/.local/state/factory/roots. The boot hook restarts every recorded repository plus $WORKSPACE_DIR, so the checkout no longer has to be the workspace mount. A repository is recorded only once its server answers. factory-up refuses when another recorded repository sets the same server.port, and a starter config takes the next free port (7731, then 7733 and up; 7732 is the dashboard's).
  • python kit: uv run|sync|add|remove refuse when the environment uv would use has a home interpreter that doesn't exist in the sandbox, such as the host's macOS .venv in a mounted checkout. That environment is $VIRTUAL_ENV with --active, else UV_PROJECT_ENVIRONMENT (relative to the workspace root), else .venv at the root uv workspace dir finds for the command's --project/--directory/UV_PROJECT. A script with inline metadata gets its own environment and is allowed. python/test-uv-sfw (47 cases) runs in CI with the pinned uv. The README and context.md also cover writing a worktree .env in setup, since upward load_dotenv() otherwise reads the main checkout's.

#14: Factory kit section

  • pi telemetry: enableInstallTelemetry: false in ~/.pi/agent/settings.json. /settings or PI_TELEMETRY=1 turns it back on.
  • SSH origin: factory-up adds url.https://github.com/.insteadOf for git@github.com: and ssh://git@github.com/ to the sandbox user's global git config. The repository config and the host are untouched.
  • git status: factory-up adds /.factory/ to .git/info/exclude.
  • .claude/skills: the README notes {"skills": ["../.claude/skills"]} in .pi/settings.json.

Python kit: no shared services

The project brings the Postgres, Redis and other services its tests need, at its own versions. This addresses #14's shared-Redis, fixed-version and tuning items by leaving services to the project.

  • Removed: sandbox-services and its boot hook, with-worktree-env, libpq-dev/postgresql-client, and the Docker Hub allow rules. build-essential and pkg-config stay.
  • Factory kit: allows Docker Hub (registry-1.docker.io, auth.docker.io, production.cloudfront.docker.com, production.cloudflare.docker.com), so the sandbox's Docker daemon can pull a project's service images. The factory contract now says so.
  • Docs: the README's "Services for tests" section says to bring services with, for example, Compose on the sandbox's Docker daemon, and how to keep parallel tickets apart (per-worktree services or separate databases and keys, recorded in .factory/CONTEXT.md). context.md points agents at .factory/CONTEXT.md.

#17: the factory binary only

From factory-skills 0.6.0 the factory binary carries the stage skills and pi's /factory extension, which factory serve writes to ~/.pi/agent/extensions/factory/ on every start, and it updates itself (/factory update, with rollback).

  • Image: the pi install git:github.com/geut/factory-skills@v… step is gone; only the binary is installed, in ~/.local/bin where the agent can replace it.
  • factory_version: default 0.6.4, now the release a new sandbox starts on.
  • README: what the kit installs; "Updating the factory"; in pi, /reload after the server (re)starts; for sandboxes from before 0.6.0, which can't run factory update: install the binary by hand, restart the server, then pi remove the pinned package it names.

Tested

  • uv guard: python/test-uv-sfw, 47 cases against the real uv with sfw stubbed, in CI with uv 0.13.8. Covers --project/--directory/UV_PROJECT in every spelling, workspace members, --active with and without VIRTUAL_ENV, UV_PROJECT_ENVIRONMENT alone and with --active, scripts with and without inline metadata, and arguments after uv run <cmd>. Each reported case also failed on the wrapper before its fix.
  • factory-up, with Herdr, curl and factory stubbed: SSH origin rewrite (once, quiet on rerun); .factory/ exclude; starter ports 7731, 7733, 7734; a port clash refused in both directions and left out of roots; the original repository restarts.
  • Telemetry build step: run against a pi settings.json; it keeps packages.

Needs a real sandbox

  • WORKSPACE_DIR in a pathless sandbox (the dashboard reads $WORKSPACE_DIR/.factory/dashboard.env): /home/agent/workspace, also the starting directory, when made with sbx create and no path (sbx run without a path mounts the current directory; README fixed in 21777dc)
  • ~/workspace is empty, so git clone … ~/workspace works: empty in a new sandbox
  • sbx exec factory mkdir -p … and sbx cp as written (since replaced by the tarball copy, sbx cp plus sbx exec … sh -c 'tar -x …', not yet run)
  • One ticket end to end from the clone in the sandbox to a pushed pull request; restart keeps it
  • Host-mounted sandbox: uv sync at the main checkout's root is refused and the host .venv survives
  • Install the factory binary only; the factory updates itself #17, new sandbox: the image has no factory-skills pi package; factory-up starts the server and /factory works in pi from the extension it installed
  • Install the factory binary only; the factory updates itself #17: /factory update in a sandbox (needs a release after the one it starts on)

🤖 Generated with Claude Code

dpaez and others added 2 commits November 17, 2026 23:59
- README: "Keep the code in the sandbox" (mountless sandbox, clone in
  ~/workspace), getting work out, lifetime, and moving an existing sandbox
- factory-up: SSH GitHub origin goes over HTTPS (global insteadOf),
  /.factory/ in info/exclude, records the repository for autostart
- factory-autostart: restarts every repository factory-up ran in
- factory image: pi's install telemetry off by default
- python: uv refuses run/sync/add/remove on a .venv from another
  interpreter (the host's); docs on worktree .env and upward dotenv

Refs #14, #15

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The project brings the services its tests need, at its own versions.
Removes sandbox-services and its boot hook, with-worktree-env,
libpq-dev and postgresql-client, and the Docker Hub allow rules. The
README says how a project brings its own services and keeps parallel
tickets apart.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dpaez dpaez changed the title Keep the code in the sandbox; factory-up git prep; pi telemetry off Keep the code in the sandbox; factory-up git prep; pi telemetry off; python kit without services Nov 18, 2026
dpaez and others added 4 commits November 18, 2026 02:53
The sandbox's Docker daemon can pull images, such as the services a
project's tests run, now that the python kit no longer brings its own.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
sbx run always mounts a workspace (the current directory when no path is
given); only sbx create with no path makes a sandbox without a mount.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@diegop-valence

Copy link
Copy Markdown

some findings:

Make the .venv guard check the project uv actually selected. I reproduced this with the PR wrapper and its pinned uv version. From the repo root, uv sync --project nested proceeded and replaced nested/.venv even though it pointed at a missing interpreter. The reverse also happened. A foreign root .venv blocked a safe sync targeting the nested project. I’d fix this before relying on the guard for host-mounted checkouts and add a regression test for both cases.

Detect port conflicts when restarting multiple repositories. Autostart now walks every registered repo, but each starter config uses port 7731. Once the first server is healthy, factory-up sees that same /health response for the second repo and skips starting its server. I’d have it report the conflict and require distinct ports if multiple repos are supported.

Document Docker disk sizing and what to bring over. After moving PostgreSQL off its 4 GiB tmpfs, our full suite also filled the sandbox’s roughly 10 GiB Docker volume. The replacement sandbox has 40 GiB. Add DOCKER_SANDBOXES_DOCKER_SIZE=40g sbx create … as an optional example for heavier workloads. It applies at creation. The guide also says to copy only FACTORY.json and CONTEXT.md, which would leave behind any setup or validation scripts those files reference. Our config calls both from .factory/bin.

…licts

- uv-sfw asks uv for the workspace root (uv workspace dir) with the
  command's --project, --directory or UV_PROJECT, and checks that .venv,
  instead of the nearest .venv above the current directory. Adds
  python/test-uv-sfw and a CI job that runs it with the pinned uv.
- factory-up stops when another recorded repository sets the same
  server.port, and a starter config takes the next free port (skipping the
  dashboard's 7732).
- README: Docker volume size at creation (DOCKER_SANDBOXES_DOCKER_SIZE),
  and copy the files FACTORY.json and CONTEXT.md reference, such as
  .factory/bin.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dpaez

dpaez commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks, all three are addressed in c99306f.

.venv guard. The wrapper now asks uv which project the command targets: it runs uv workspace dir with the command's --project, --directory (both =value forms too) or UV_PROJECT, and checks <workspace root>/.venv. That's the environment uv itself uses, workspace members included. uv workspace dir doesn't resolve, so it works offline and before a lockfile exists. Both of your cases are covered, along with options before the subcommand (uv --project nested sync used to skip the guard). Arguments after uv run <cmd> aren't read, and --active, --no-project and --script skip the guard. python/test-uv-sfw has 26 cases, and the old wrapper fails 11 of them. A new test uv-sfw guard job in Validate kits runs it with the uv the kit pins.

Port conflicts. /health only returns an instance ID, so factory-up compares configs instead. It stops with an error when another repository in ~/.local/state/factory/roots sets the same server.port, before a healthy answer can be taken for this repository's server. The error says to give each repository its own port or to remove a stale line. A new repository's starter config takes the next free port, skipping the dashboard's 7732 (7731, 7733, 7734…). Autostart logs the error and moves on to the next repository.

Docs.

  • Both setup paths now say the Docker volume is 10 GiB by default and fixed at creation, and show DOCKER_SANDBOXES_DOCKER_SIZE=40g sbx create … (or sbx settings set sandbox.disk.dockerVolume 40g for all new sandboxes). The python README's tests section points there.
  • The setup step now copies FACTORY.json, CONTEXT.md and everything they reference, such as .factory/bin, as one tarball, which keeps the scripts executable. It also lists what to leave out.

@diegop-valence

Copy link
Copy Markdown

New findings:

Some uv flags still let it replace a host .venv. The original --project cases now pass with the pinned uv version. But the guard skips --active and --script outright. With VIRTUAL_ENV unset, uv sync --active still uses the project’s .venv. So does uv run --script for a script without inline dependency metadata. I reproduced both commands deleting and recreating a foreign .venv. The guard should check the project environment when uv falls back to it. Guard code
2. A rejected repo can block a working repo from restarting. New configs correctly get distinct ports. But factory-up records a repo before checking for conflicts. I tried adding a second repo with an existing config on 7731. It was rejected, yet its entry stayed in roots and blocked the original repo on the next autostart. Registering the repo after successful startup would prevent that. Registration · Conflict check

…ed repos only

- uv-sfw checks $VIRTUAL_ENV with --active, and the project's .venv when it
  is unset. `uv run --script` and `uv run x.py` check the project's .venv
  unless the script has inline metadata, which gets its own environment.
  Adds 14 test cases.
- factory-up adds a repository to the autostart roots only after its server
  answers, so a repository rejected for a port conflict doesn't block the
  one it conflicted with on the next boot.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dpaez

dpaez commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, both are fixed in 0455b31. I reproduced each one with the real uv first.

--active and --script. The guard no longer skips these. It checks the environment uv falls back to:

  • --active: checks $VIRTUAL_ENV when it's set. When it isn't, the guard checks the project's .venv. A foreign $VIRTUAL_ENV was also being replaced by uv sync --active, so that's covered too.
  • Scripts: uv run --script x.py and uv run x.py check the project's .venv unless the script has a # /// script block. uv runs those in an environment of their own and leaves .venv alone, so they're allowed now. The previous wrapper wrongly blocked uv run x.py for such a script.
  • Script environments: uv sync --script and uv add --script only touch the script's environment, so they're still allowed.

python/test-uv-sfw has 14 new cases (40 in total). The previous wrapper fails 7 of them, including both of yours.

Rejected repo blocking restarts. factory-up now adds a repository to ~/.local/state/factory/roots only after its server answers on /health. I ran your scenario with stubbed Herdr, curl and factory:

  1. A starts on 7731 and is registered.
  2. B, also on 7731, is rejected and stays out of roots.
  3. Rerunning factory-up for A, as autostart does, works.
  4. B moves to 7733, starts, and is registered.

An entry left behind by the previous version still has to be removed from roots by hand.

@diegop-valence

Copy link
Copy Markdown

New finding:

Remaining issue: Setting UV_PROJECT_ENVIRONMENT skips the guard entirely. When VIRTUAL_ENV also points at a foreign environment, uv sync --active uses that active environment anyway. I reproduced uv deleting and recreating it. I’d ask upstream to check the active environment first and add a regression test for the two variables together. Guard code

With UV_PROJECT_ENVIRONMENT set, the guard skipped every check, yet
`uv sync --active` still replaces a foreign $VIRTUAL_ENV, and uv replaces a
foreign UV_PROJECT_ENVIRONMENT too. The guard now checks the environment uv
picks: $VIRTUAL_ENV with --active, else UV_PROJECT_ENVIRONMENT (relative to
the workspace root), else the workspace root's .venv. Adds 7 test cases.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dpaez

dpaez commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, fixed in 478c23a. I reproduced it, and found a related case: when UV_PROJECT_ENVIRONMENT itself points at a foreign environment, uv replaces that one too.

The guard no longer skips when UV_PROJECT_ENVIRONMENT is set. It checks the environment uv will use, in uv's order:

  1. $VIRTUAL_ENV, for --active when it's set.
  2. UV_PROJECT_ENVIRONMENT, absolute or relative to the workspace root (that's how uv resolves it).
  3. .venv at the workspace root.

Pointing UV_PROJECT_ENVIRONMENT at a new directory still works as the way out.

python/test-uv-sfw adds 7 cases for the two variables together and for a foreign UV_PROJECT_ENVIRONMENT, 47 in total. The previous wrapper fails the 3 blocking cases, including yours.

dpaez and others added 2 commits November 20, 2026 15:53
From factory-skills 0.6.0 the binary carries the stage skills and the
operator's Pi extension, which `factory serve` writes to Pi's agent
directory on every start, and it updates itself. Drop the factory-skills Pi
package from the image, and default factory_version to 0.6.4, the release
a new sandbox starts on. README: what the kit installs, updating the
factory, and how a sandbox from before 0.6.0 moves over (install the binary
by hand, then `pi remove` the pinned package).

Closes #17

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ory version

- factory/context.md: /factory comes from the extension `factory serve`
  writes to ~/.pi/agent/extensions/factory/, not the factory-skills package.
- README: the manual install for older sandboxes downloads the latest
  release (no tag) and prints its version.
- The image build checks `factory --version` against FACTORY_VERSION
  instead of running --help, and factory_version accepts 0.6.0 or later.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dpaez
dpaez merged commit 36e5d20 into main Nov 20, 2026
11 of 12 checks passed
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.

Install the factory binary only; the factory updates itself

2 participants