- Prefix Isolation - All tools installed in a self-contained directory
- Sandbox Mode - Optional process-level filesystem protection
Prefix Installation
When you runnightshift install --prefix <prefix>, Nightshift creates a self-contained environment with:
- OpenCode - The coding agent harness
- uv - Python toolchain manager (handles Python installation, packages, and virtual environments)
- ripgrep - Fast code search
Environment Variables
Therun() function in src/index.ts:968 configures the environment when launching the agent:
PATHincludesworkspace/.venv/bin,uv-tools/bin, andprefix/bin- XDG variables (
XDG_CONFIG_HOME,XDG_CACHE_HOME, etc.) point to prefix subdirectories viabuildXdgEnv() - uv variables (
UV_PYTHON_INSTALL_DIR,UV_PYTHON_PREFERENCE) viabuildUvEnv() HOME,USER,TERM, andLANGare passed through from your shell
How Python Imports Work
The workspace contains a Python package atsrc/<library>/. When uv sync runs, it installs this package in editable mode into the virtual environment’s site-packages. This means from agent_lib.utils import hello works automatically.
Since PATH places .venv/bin first, both python script.py and uv run python script.py use the same interpreter with the editable install—no PYTHONPATH manipulation needed.
Python Management with uv
Nightshift delegates all Python management to uv, Astral’s fast Python toolchain. This provides complete isolation from any system Python installation.How It Works
ThesyncWorkspace() function in src/index.ts:553 runs uv sync during installation. When executed, uv automatically:
- Downloads Python from python-build-standalone if no suitable version exists
- Creates a virtual environment at
workspace/.venv - Installs dependencies from
pyproject.toml - Locks versions in
uv.lockfor reproducibility
Environment Configuration
ThebuildUvEnv() helper in src/index.ts:181 configures uv with two environment variables:
| Variable | Value | Purpose |
|---|---|---|
UV_PYTHON_INSTALL_DIR | <prefix>/python | Store Python installations inside the prefix |
UV_PYTHON_PREFERENCE | only-managed | Ignore system Python, only use uv-managed versions |
Python Version
ThegenerateRootPyproject() function in src/index.ts:336 generates a pyproject.toml with:
<prefix>/python/. The virtual environment at workspace/.venv/bin/python links to this installation.
Package Management
Agents are instructued to manage dependencies using uv commands:CLI Tools
TheinstallUvTools() function in src/index.ts:572 uses uv tool to install standalone CLI tools:
<prefix>/uv-tools/ to keep them separate from the workspace. Currently, Nightshift installs ty (the type checker) this way.
This also ensures that Opencode will have an LSP to use when running regardless of if there is one installed on the host system.
Workspace Structure
The workspace is a uv-managed Python project that the agent maintains:Bootstrap Process
During installation, Nightshift runs a bootstrap Agent Routine process where the agent:- Reads a user-provided
BOOT.mdfile (if present) describing the intended use case - Interviews the user about their requirements
- Installs appropriate packages via
uv add - Generates
AGENTS.mdwith project-specific instructions - Creates skills in
.opencode/skills/
Sandbox Mode
For additional security, enable sandbox mode with the--sandbox flag:
- The workspace directory
- The prefix directory (for caches and state)
- Temporary directories (
/tmp,/var/tmp)
Platform Support
macOS uses the built-insandbox-exec with a custom profile:
- No additional installation required
- Uses Apple’s sandbox technology
bwrap):
- Install with:
apt install bubblewrap(Debian/Ubuntu) ordnf install bubblewrap(Fedora) - Creates a containerized environment with bind mounts
- Some legitimate workflows need broader filesystem access
- The prefix isolation already provides meaningful separation
