Skip to content

armgit / qm

Public Imported from GitHub
0

Multiplayer agent harness for work.

Install Python packages with uv in the default Modal image (#2034)

Joshua France2b1bcc97a221
diff --git a/docs/modal-image.md b/docs/modal-image.md
index 973bf6639..87529efac 100644
--- a/docs/modal-image.md
+++ b/docs/modal-image.md
@@ -19,9 +19,13 @@ for building and running; `MODAL_ENVIRONMENT` selects the SDK environment. The b
does not change running sandboxes or deploy core.
With no `MODAL_IMAGE` set during the build, the image starts from QM's pinned Node
-base and installs its usual shell, Python, Git, curl, and archive utilities. To extend
-an existing custom image, set `MODAL_IMAGE` to its registry reference (prefer an
-immutable digest) or an existing Modal image ID. Custom bases must already contain
+base and installs its usual shell, Python, Git, curl, and archive utilities. It also
+installs a pinned, checksum-verified `uv`, configures `uv pip install` to target the
+system Python without a virtual environment, and preinstalls pinned requests,
+beautifulsoup4, lxml, openpyxl, pypdf and python-docx. Packages installed later with
+`uv pip install` land in `/usr/local`, outside home checkpoints, so they last until the
+sandbox is replaced. To extend an existing custom image, set `MODAL_IMAGE` to its
+registry reference (prefer an immutable digest) or an existing Modal image ID. Custom bases must already contain
Node, npm, and QM's baseline utilities; this preserves the existing custom-image
contract. Building again from the same inputs uses Modal's layer cache.
diff --git a/src/sandbox/modal-image.ts b/src/sandbox/modal-image.ts
index 401ff1130..0a3c7d43b 100644
--- a/src/sandbox/modal-image.ts
+++ b/src/sandbox/modal-image.ts
@@ -2,8 +2,23 @@ import type { ModalClient } from "modal";
export const MODAL_DEFAULT_IMAGE =
"node:24-slim@sha256:6f7b03f7c2c8e2e784dcf9295400527b9b1270fd37b7e9a7285cf83b6951452d";
+const PYTHON_PACKAGES = [
+ "beautifulsoup4==4.15.0",
+ "lxml==6.1.3",
+ "requests==2.34.2",
+ "openpyxl==3.1.5",
+ "pypdf==6.19.0",
+ "python-docx==1.2.0",
+];
+const UV_VERSION = "0.12.19";
+const UV_SHA256 = "23bf5552d220e0842b65c862097b2ebaeba0064b74eda5e565e77fd25969d8c8";
export const MODAL_DEFAULT_IMAGE_SETUP =
- "RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates curl git jq tar xz-utils unzip python3 python3-venv openssh-client && rm -rf /var/lib/apt/lists/*";
+ "RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates curl git jq tar xz-utils unzip python3 python3-venv openssh-client && rm -rf /var/lib/apt/lists/*" +
+ ` && curl -fsSL -o /tmp/uv.tgz https://github.com/astral-sh/uv/releases/download/${UV_VERSION}/uv-x86_64-unknown-linux-gnu.tar.gz` +
+ ` && echo "${UV_SHA256} /tmp/uv.tgz" | sha256sum -c -` +
+ " && tar -xzf /tmp/uv.tgz -C /usr/local/bin --strip-components=1 && rm /tmp/uv.tgz" +
+ " && mkdir -p /etc/uv && printf '[pip]\\nsystem = true\\nbreak-system-packages = true\\n' > /etc/uv/uv.toml" +
+ ` && uv pip install --no-cache --only-binary=:all: ${PYTHON_PACKAGES.join(" ")}`;
export async function resolveModalImage(client: ModalClient, reference?: string) {
if (reference?.startsWith("im-")) return client.images.fromId(reference);
diff --git a/test/modal-image.test.ts b/test/modal-image.test.ts
index 6330ed5ac..4aecf0750 100644
--- a/test/modal-image.test.ts
+++ b/test/modal-image.test.ts
@@ -43,3 +43,10 @@ test("Modal preserves custom registry images and the default baseline", async ()
["commands", [MODAL_DEFAULT_IMAGE_SETUP]],
]);
});
+
+test("Modal default baseline installs uv and common Python packages system-wide", () => {
+ assert.match(MODAL_DEFAULT_IMAGE_SETUP, /astral-sh\/uv\/releases\/download\/\d+\.\d+\.\d+\//);
+ assert.match(MODAL_DEFAULT_IMAGE_SETUP, /sha256sum -c -/);
+ assert.match(MODAL_DEFAULT_IMAGE_SETUP, /system = true\\nbreak-system-packages = true/);
+ assert.match(MODAL_DEFAULT_IMAGE_SETUP, /uv pip install .*beautifulsoup4==/);
+});