Skip to content

Add: python mixin kit for running the factory on Python projects - #12

Merged
dpaez merged 4 commits into
mainfrom
dp/python-kit
Nov 16, 2026
Merged

dpaez merged 4 commits into
mainfrom
dp/python-kit

Conversation

@dpaez

@dpaez dpaez commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Refs #11. A slim python mixin for the factory. It provides the Python dependencies; each project keeps its own setup. Some acceptance criteria still need a real sbx sandbox or a factory-skills release (see Not done yet).

What's in it

python/ mixin (requires io.github.geut/pi-factory >= 1, provides io.github.geut/python@1), about 54 MB:

  • uv and uvx in /usr/local/bin are wrappers that run the real binaries through sfw. Package downloads go through Socket Firewall for shell-less factory commands too, with no aliases.
  • /etc/uv/uv.toml:
    • python-preference = "only-managed": uv-managed CPython with headers, following .python-version.
    • link-mode = "copy": worktrees are on the host mount and the cache is in $HOME.
  • Install hook (root, at sandbox creation): apt-get install build-essential pkg-config libpq-dev postgresql-client. The install network phase allows the Ubuntu archives plus the Docker and GitHub CLI apt repositories that apt-get update refreshes.
  • sandbox-services: a shared Postgres 18 (dev/dev, CREATEDB) and Redis 8 on the in-sandbox daemon, started by a startup hook (start --wait-for-docker).
  • with-worktree-env: sets a stable WORKTREE_ID per worktree.
  • context.md and README.md: a starter FACTORY.json and Django / SQLAlchemy / Celery isolation notes.

Factory: api.linear.app added to runtime.allow.

Workflows:

  • Publish builds the python tag.
  • A new Validate kits workflow builds the kits a PR changes with the kit frontend, then runs kit-tck validate (pinned v3.0.0-m.12, checksum-verified) on the OCI layout.

README: pointers to the kit, the Linear key setup, and the Validate section.

Decisions worth a look

  • apt at creation, not baked. The factory's apt-get purge xz-utils && apt-get autoremove removes gcc. An install hook keeps the packages dpkg-managed and consistent with the image, at about 45 s per sandbox creation. This follows docker/sbx-kits-contrib's packages-through-sfw.
  • The sfw wrapper wraps every uv command. A command under uv run inherits sfw's proxy and CA bundle while it runs. /usr/local/lib/python-kit/bin/uv skips it.
  • Dropped from the first version:
    • the preinstalled interpreter (the factory's Ubuntu python3 3.14 has no headers);
    • just, because it's a project choice;
    • the services and version args;
    • python/example and python/check.
  • sbx-kits-contrib's Go TCK isn't used. Its e2e harness composes a mixin onto a built-in agent, and this kit requires the factory. kit-tck from docker/sandbox-kit-spec validates the built artifact instead.

Tested (arm64, by hand)

The mixin was built with plain docker build, composed onto the published node-24-factory image, and the hooks were run by hand:

  • The install hook succeeds (44 s). gcc, psql and pkg-config libpq work.
  • sandbox-services start --wait-for-docker brings both services up, and a second start is a no-op (0.19 s).
  • uv sync goes through sfw (sfw's proxy and CA appear in the environment), downloads a managed 3.13, and builds psycopg-c from source.
  • A second worktree's uv sync --frozen --offline succeeds with no warnings.
  • Two worktrees ran Postgres-backed tests at the same time through with-worktree-env, and both passed.
  • uv run works with no shell, and uvx ruff works.
  • docker buildx build ./python -f python/python.yaml with the kit frontend: no errors or warnings.

kit-tck hasn't run yet; the new workflow on this PR is its first run.

Not done yet

  • factory_version bump. factory-skills has the Linear adapter on main, but the latest release is still v0.2.0.
  • Needs a real sbx sandbox:
    • composition, and refusal on pi and pi-docker;
    • the install hook under sbx's deny-by-default policy;
    • services after sbx stop/sbx run;
    • Linear's bare Authorization header through the proxy;
    • project skills in factory panes;
    • one ticket end to end.
  • amd64.

🤖 Generated with Claude Code

dpaez and others added 4 commits November 15, 2026 14:37
- python/ mixin (requires io.github.geut/pi-factory >= 1): uv, just and a
  preinstalled CPython in /usr/local/bin; gcc, libpq headers, psql and
  pg_isready, shipped with their dependency closure because the factory
  image removes the compiler
- sandbox-services: one shared Postgres and Redis on the in-sandbox Docker
  daemon, started by a lifecycle hook that also adds sfw aliases for pip/uv
- with-worktree-env: a stable WORKTREE_ID per worktree for test database
  names and key prefixes
- python/example (Django, two aliases, Redis cache) and python/check
- factory: allow api.linear.app; publish workflow builds the python tag
- README: Python projects section, Linear key setup, mixin notes

Refs #11

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Install build-essential, pkg-config, libpq-dev and postgresql-client
  with a lifecycle install hook (root, at sandbox creation) instead of
  copying a package closure into the image: dpkg-managed, no loader cache
  or library version skew. The mixin image goes from ~580 MB to ~54 MB.
- uv and uvx in /usr/local/bin are wrappers that run the real binaries
  through sfw, so shell-less factory commands are covered; drop the bash
  aliases and the startup script that appended them.
- uv uses only managed CPython (headers, follows .python-version); drop
  the preinstalled interpreter, just, and every arg but uv_version.
- sandbox-services: fixed Postgres 18 + Redis 8, boot mode via
  --wait-for-docker.
- Remove python/example, python/check and collect-packages; move the
  Python docs to python/README.md and keep the main README to pointers.
- Validate kits workflow: build changed kits with the kit frontend and run
  kit-tck validate on the OCI layout.

Refs #11

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Allow releases.astral.sh: uv downloads managed CPython from Astral's
  mirror, and only-managed has no fallback.
- sandbox-services checks Postgres readiness over TCP, so the first-boot
  init server (socket only) no longer races the role setup.
- with-worktree-env always derives WORKTREE_ID from the worktree.
- uv run --no-sync/--offline (or UV_NO_SYNC/UV_OFFLINE) skips sfw; the
  starter validation commands use --no-sync.
- Factory contract: sfw on PATH, the in-sandbox Docker daemon, Ubuntu
  26.04 and its apt sources.
- Validate kits: derive kits from <kit>/<kit>.yaml, and build both
  platforms for recipes that download on $BUILDPLATFORM.

Refs #11

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dpaez
dpaez merged commit 2559821 into main Nov 16, 2026
5 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.

1 participant