Runtime Execution Model
This document explains how vnma runs scripts, loads packages hermetically, and resolves dynamic libraries without virtual environments.
1. Running Applications with vnma run
To execute an application script with the vendored runtime active:
vnma run main.py -- --option value
Process Lifecycle
When invoking vnma run:
vnmalocates the project root and its vendor directory.- It sets up environment variables:
PYTHONPATHincludesvendor/.vnma_meta/site(housingsitecustomize.py) andvendor/.PATHprependsvendor/.vnma_meta/.bin/to expose installed CLI tools.PYTHONNOUSERSITE=1blocks user-site directories from loading.
- It launches the Python interpreter directly:
Because execution does not usepython main.py --option valuepython -c "exec(...)",sys.argv[0]correctly points tomain.py, preserving compatibility withargparse,sys.argvinspection, and themultiprocessingmodule.
2. Direct Python Execution (import vendor.__bootstrap__)
If you prefer to launch your application directly via python main.py without using the vnma CLI:
Add the bootstrap import at the top of your entry file:
import vendor.__bootstrap__
import requests
import pygame
# Application code follows...
Run vnma insert-import to add this line automatically. See Entry Points Without vnma run.
3. Runtime Path Isolation
it isolates your application execution:
- It identifies standard library paths (
stdlib,platstdlib, interpreter zip files). - It identifies global package directories:
purelibandplatlib(systemsite-packages).- User site-packages (
site.getusersitepackages()). - Distribution package paths (
dist-packages).
- It filters
sys.pathin place, removing global and user third-party packages while retaining Python's standard library and the localvendor/directory.
This prevents the common issue where code succeeds locally because a dependency exists in the developer's system Python, but fails when deployed to a clean container.
4. Windows Native DLL Registration
On Windows with Python 3.8+, Python no longer searches the system PATH for DLLs required by compiled extensions (.pyd).
Instead of performing recursive filesystem scans (os.walk) during startup, vnma records the exact relative directories containing .dll files in a static tuple during installation:
_DLL_SUBDIRS = ['pygame', 'pygame/_sdl2']
At startup:
__bootstrap__.pyiterates over_DLL_SUBDIRS.- It verifies that each path is strictly confined within
VENDOR_ROOT(preventing DLL hijacking via external symlinks). - It invokes
os.add_dll_directory()and retains the resulting handle in a global collection_DLL_HANDLESto prevent premature garbage collection.
5. CLI Executables (vnma exec)
When packages declare console scripts (e.g., pytest, black, my-tool):
vnmagenerates executable wrapper scripts invendor/.vnma_meta/.bin/.- Wrappers configure
PYTHONPATHand launch the tool using the host Python interpreter.
To invoke an installed tool:
vnma exec my-tool --help
# or directly on Windows:
.\vendor\.vnma_meta\.bin\my-tool.cmd --help