Skip to content

Quickly sandbox your AI agent.

Python

fix: trust pip's exit code in auto_install_images

Tyler Paynef29a776a3a9c
diff --git a/packages/quicksand-core/quicksand_core/_auto_install.py b/packages/quicksand-core/quicksand_core/_auto_install.py
index 9ef5c4a..2284c5b 100644
--- a/packages/quicksand-core/quicksand_core/_auto_install.py
+++ b/packages/quicksand-core/quicksand_core/_auto_install.py
@@ -6,6 +6,12 @@ against the quicksand simple index — which serves every wheel from every
per-package GitHub release — to upgrade the install to the platform-specific
fat wheel carrying the actual images.
+The Python code in the slim and fat wheels is identical; only the bundled
+image data differs. Pip's ``--force-reinstall`` swaps the files on disk
+under the same ``site-packages`` location, and the calling provider's
+``IMAGES_DIR`` `Path` continues to resolve to that location — so resolution
+can continue in-process after this function returns.
+
Enabled by default; set ``QUICKSAND_AUTO_INSTALL=0`` to opt out.
"""
@@ -25,16 +31,6 @@ logger = logging.getLogger("quicksand.auto_install")
_TRUTHY = {"1", "true", "yes", "on"}
-class ImagesInstalled(Exception):
- """Raised after :func:`auto_install_images` successfully installs a wheel.
-
- Signals the caller that images were written to disk but the running
- Python process has stale module / entry-point state from before the
- install. The operation should be retried in a fresh process; the CLI
- entry point catches this and ``os.execv``s back into the same command.
- """
-
-
def auto_install_images(package_name: str, images_dir: Path) -> bool:
"""Re-install *package_name* against the quicksand simple index.
@@ -43,22 +39,25 @@ def auto_install_images(package_name: str, images_dir: Path) -> bool:
index, which serves the fat wheel from the matching per-package GitHub
release; pip drops the images into the package's site-packages dir.
+ The caller is expected to validate that the resulting files are
+ actually present (e.g. checking for ``manifest.json`` or a specific
+ qcow2) — different contrib packages lay out their image data
+ differently, so this function only reports whether pip succeeded.
+
Enabled by default; set ``QUICKSAND_AUTO_INSTALL=0`` to opt out.
Args:
package_name: PyPI package name (e.g. ``"quicksand-ubuntu"``).
- images_dir: Expected images directory — used only to verify that
- the reinstall actually placed images.
+ images_dir: Reserved for future use; currently unused but kept in
+ the signature for backwards compatibility with the previous
+ download-and-extract implementation.
Returns:
- ``False`` if auto-install is disabled or fails.
-
- Raises:
- ImagesInstalled: When pip successfully installs the new wheel.
- Pip subprocess runs cleanly, but the parent process still holds
- references to the previous (pure-stub) module, so continuing
- in-process is unreliable — bubble up to the CLI for a re-exec.
+ True if pip exited successfully, False otherwise (auto-install
+ disabled, unknown version, pip failure).
"""
+ del images_dir # kept for API compatibility; pip handles file placement
+
val = os.environ.get("QUICKSAND_AUTO_INSTALL", "1").strip().lower()
if val not in _TRUTHY:
return False
@@ -93,9 +92,4 @@ def auto_install_images(package_name: str, images_dir: Path) -> bool:
logger.warning("pip install failed (exit %s)", result.returncode)
return False
- if not (images_dir / "manifest.json").exists():
- # Pip succeeded but the new wheel didn't drop a manifest. Treat as
- # a soft failure so callers can fall back to their own error path.
- return False
-
- raise ImagesInstalled(package_name)
+ return True
diff --git a/packages/quicksand-core/quicksand_core/qemu/image_resolver.py b/packages/quicksand-core/quicksand_core/qemu/image_resolver.py
index 5f3f04a..04a0587 100644
--- a/packages/quicksand-core/quicksand_core/qemu/image_resolver.py
+++ b/packages/quicksand-core/quicksand_core/qemu/image_resolver.py
@@ -15,7 +15,6 @@ import logging
from importlib.metadata import entry_points
from pathlib import Path
-from .._auto_install import ImagesInstalled
from .._types import FilePatterns, ResolvedImage, SaveManifest
from ..host.arch import Architecture, _detect_architecture
@@ -201,10 +200,6 @@ class ImageResolver:
)
logger.info("Resolved base image via entry point: %s", name)
return result
- except ImagesInstalled:
- # Auto-install fired during this lookup; the in-process state
- # is now stale. Bubble up to the CLI for a clean re-exec.
- raise
except Exception:
logger.debug("Failed to load entry point %s", ep.name, exc_info=True)
continue
diff --git a/packages/quicksand/quicksand/cli/__init__.py b/packages/quicksand/quicksand/cli/__init__.py
index f7d0ea0..5587f89 100644
--- a/packages/quicksand/quicksand/cli/__init__.py
+++ b/packages/quicksand/quicksand/cli/__init__.py
@@ -3,27 +3,13 @@
from __future__ import annotations
import argparse
-import os
import sys
-from quicksand_core._auto_install import ImagesInstalled
-
from . import clean, dev, install, list_extras, qemu, run, uninstall
def main() -> int:
"""Main entry point for the quicksand CLI."""
- try:
- return _dispatch()
- except ImagesInstalled as e:
- # A provider auto-installed its fat wheel mid-resolve. Pip ran in a
- # subprocess so the parent's in-memory module state is stale —
- # restart the process so subsequent resolution sees a clean slate.
- print(f"\nInstalled images for {e}; restarting...\n", flush=True)
- os.execv(sys.executable, [sys.executable, *sys.argv])
-
-
-def _dispatch() -> int:
parser = argparse.ArgumentParser(
prog="quicksand",
description="A VM harness for AI agents.",