diff --git a/Dockerfile.sandbox b/Dockerfile.sandbox index b028908c..bb3a876b 100644 --- a/Dockerfile.sandbox +++ b/Dockerfile.sandbox @@ -22,10 +22,15 @@ ENV NODE_PATH=/usr/local/lib/node_modules # and pip caches, git config, gh config, the pnpm store) fails with EACCES. # Point HOME at a sticky world-writable directory and give corepack a shared # prewarmed cache so the preinstalled pnpm resolves without network or root. +# PNPM_CONFIG_STORE_DIR pins the pnpm store to a container-internal path: +# pnpm 11 no longer reads npm_config_* env vars, and an unpinned store falls +# back into the bind-mounted project directory, where it floods the host file +# watcher and gets committed. ENV HOME=/home/ocm-agent ENV COREPACK_HOME=/usr/local/share/corepack ENV UV_TOOL_BIN_DIR=/opt/agent-tools/bin ENV PNPM_HOME=/opt/agent-tools +ENV PNPM_CONFIG_STORE_DIR=/home/ocm-agent/.local/share/pnpm/store ENV PATH=/opt/agent-tools/bin:$PATH RUN echo "Installing gh and CLI tooling (cachebust=${TOOLS_CACHEBUST})" && \ diff --git a/backend/test/scripts/docker-config.test.ts b/backend/test/scripts/docker-config.test.ts index 3501494a..9580e1fa 100644 --- a/backend/test/scripts/docker-config.test.ts +++ b/backend/test/scripts/docker-config.test.ts @@ -224,6 +224,16 @@ describe('docker lifecycle scripts', () => { }) }) +describe('sandbox guest image', () => { + const sandboxDockerfilePath = join(repoRoot, 'Dockerfile.sandbox') + const sandboxDockerfile = read(sandboxDockerfilePath) + + it('pins the pnpm store to a container-internal path via PNPM_CONFIG_STORE_DIR', () => { + expect(sandboxDockerfile).toContain('PNPM_CONFIG_STORE_DIR=/home/ocm-agent/.local/share/pnpm/store') + expect(sandboxDockerfile, 'pnpm 11 ignores npm_config_* env vars').not.toContain('npm_config_store_dir=') + }) +}) + describe('sandbox compose overlay', () => { const overlayPath = join(repoRoot, 'docker-compose.sandbox.yml') const overlay = read(overlayPath) diff --git a/docker-compose.sandbox.yml b/docker-compose.sandbox.yml index 03512e8f..3f21f3a5 100644 --- a/docker-compose.sandbox.yml +++ b/docker-compose.sandbox.yml @@ -16,7 +16,7 @@ services: cap_add: - NET_ADMIN environment: - - SANDBOX_IMAGE=${SANDBOX_IMAGE:-docker.io/cstechdev/ocm-sandbox@sha256:10e2ca3c93883441538b5f6008caee28ec88ec842cbdbdfed0b7a459d80f1583} + - SANDBOX_IMAGE=${SANDBOX_IMAGE:-docker.io/cstechdev/ocm-sandbox@sha256:edec46ffc48bd23fdd36b732492df7c5da5acd687ba0383e66ee28bc7c78770f} - SANDBOX_MEMORY=${SANDBOX_MEMORY:-4G} - SANDBOX_CPUS=${SANDBOX_CPUS:-2} - SANDBOX_EXEC_USER=${SANDBOX_EXEC_USER:-${PUID:-1000}} diff --git a/docs/configuration/docker.md b/docs/configuration/docker.md index 2707a31d..0aebff14 100644 --- a/docs/configuration/docker.md +++ b/docs/configuration/docker.md @@ -330,7 +330,7 @@ services: cap_add: - NET_ADMIN environment: - - SANDBOX_IMAGE=${SANDBOX_IMAGE:-docker.io/cstechdev/ocm-sandbox@sha256:10e2ca3c93883441538b5f6008caee28ec88ec842cbdbdfed0b7a459d80f1583} + - SANDBOX_IMAGE=${SANDBOX_IMAGE:-docker.io/cstechdev/ocm-sandbox@sha256:edec46ffc48bd23fdd36b732492df7c5da5acd687ba0383e66ee28bc7c78770f} - SANDBOX_MEMORY=${SANDBOX_MEMORY:-4G} - SANDBOX_CPUS=${SANDBOX_CPUS:-2} - SANDBOX_EXEC_USER=${SANDBOX_EXEC_USER:-${PUID:-1000}} diff --git a/docs/configuration/environment.md b/docs/configuration/environment.md index a4d868f4..3b8e08b9 100644 --- a/docs/configuration/environment.md +++ b/docs/configuration/environment.md @@ -116,7 +116,7 @@ Sandboxed agent commands run inside a microVM managed by `msb` (see [Agent Sandb |----------|-------------|---------| | `MSB_PATH` | Path to the `msb` executable | `msb` | | `MSB_LIBKRUNFW_PATH` | Path to the `libkrunfw` firmware library used by `msb` (set in the container image) | `/opt/microsandbox/lib/libkrunfw.so` | -| `SANDBOX_IMAGE` | OCI image the microVM boots from. Digest-pinned by default so a rebuilt guest image is actually adopted; see [Sandbox Guest Image](../features/sandboxing.md#sandbox-guest-image) for what the default ships and how to build your own | `docker.io/cstechdev/ocm-sandbox@sha256:10e2ca3c…` | +| `SANDBOX_IMAGE` | OCI image the microVM boots from. Digest-pinned by default so a rebuilt guest image is actually adopted; see [Sandbox Guest Image](../features/sandboxing.md#sandbox-guest-image) for what the default ships and how to build your own | `docker.io/cstechdev/ocm-sandbox@sha256:edec46ff…` | | `SANDBOX_MEMORY` | MicroVM memory (e.g. `4G`) | `4G` | | `SANDBOX_CPUS` | MicroVM CPU count | `2` | | `SANDBOX_EXEC_USER` | Guest identity sandboxed commands run as: a numeric `uid`, a numeric `uid:gid`, or a guest username. A numeric uid must match the Manager's effective uid (`PUID`); the compose overlay defaults it to `${PUID:-1000}`. A guest username is resolved to the Manager's effective `uid:gid` so writes to the mounted project roots always succeed. When a configured numeric identity cannot write the workspace, enforcement is reported unavailable | `${PUID:-1000}` via the overlay, otherwise `node` | diff --git a/docs/features/sandboxing.md b/docs/features/sandboxing.md index e42fa01f..f5572ced 100644 --- a/docs/features/sandboxing.md +++ b/docs/features/sandboxing.md @@ -193,6 +193,8 @@ It is `node:24` (Debian 12, `buildpack-deps` based), so the compile toolchain is The guest runs every command as a numeric host uid that has no `/etc/passwd` entry in the image, so the uncorrected default `HOME` is `/` and anything that writes per-user state — the pnpm store, uv and pip caches, `git config`, `gh` config — dies with `EACCES` on the first run. The image therefore sets `HOME=/home/ocm-agent` (mode 1777), prewarms corepack into a world-readable `COREPACK_HOME`, and puts a world-writable `/opt/agent-tools/bin` on `PATH` for `uv tool` and global package-manager installs. Image `ENV` reaches `msb exec` commands verbatim, including for unknown uids. The image build verifies the whole toolchain as an unprivileged uid so a root-only regression fails the build instead of the agent. +The pnpm store itself is pinned to a container-internal path with `PNPM_CONFIG_STORE_DIR=/home/ocm-agent/.local/share/pnpm/store`. The pin goes through pnpm's own config env var because pnpm 11 no longer reads `npm_config_*` variables; with the store unpinned, pnpm places it on the mounted project filesystem, which pollutes the repository, slows installs over the host bind mount, and can end up committed. + `sudo` also needs the exec user to exist in the guest, which the image cannot know at build time. The Manager provisions the `/etc/passwd`, `/etc/group`, and `/etc/shadow` entries for the exec uid through an idempotent root exec (verified by `getent`, so repeats are no-ops) at three points: when the workspace sandbox is created, when a stopped sandbox is started, and at Manager startup. A freshly created microVM does not accept `msb exec` until its guest agent is up, so provisioning first waits on `msb ping` (bounded by `SANDBOX_START_TIMEOUT_MS`) instead of racing the boot. Without the entries, `sudo` refuses with "you do not exist in the passwd database" or a PAM "account validation failure". Provisioning is deliberately non-fatal: if it fails, the Manager logs a warning and the sandbox still runs commands — only `sudo` is unavailable. A microVM created from an older image reference is replaced automatically when the digest pin changes, so it picks up both sudo and the fixed toolchain without manual cleanup. Chromium launches headless as the non-root exec user without extra flags. If your host kernel restricts user namespaces so Chromium's own sandbox fails, pass `--no-sandbox` — the microVM is already the isolation boundary. diff --git a/shared/src/config/defaults.ts b/shared/src/config/defaults.ts index b7743e84..28bea551 100644 --- a/shared/src/config/defaults.ts +++ b/shared/src/config/defaults.ts @@ -33,7 +33,7 @@ export const DEFAULTS = { SANDBOX: { MSB_PATH: 'msb', - IMAGE: 'docker.io/cstechdev/ocm-sandbox@sha256:10e2ca3c93883441538b5f6008caee28ec88ec842cbdbdfed0b7a459d80f1583', + IMAGE: 'docker.io/cstechdev/ocm-sandbox@sha256:edec46ffc48bd23fdd36b732492df7c5da5acd687ba0383e66ee28bc7c78770f', MEMORY: '4G', CPUS: 2, EXEC_USER: 'node',