Expand description
Workspace environments: where the programs and libraries a run needs come from.
Models fail most often not on the task but on a missing tool (jq: not found,
No module named 'matplotlib', a pip install that can’t work on NixOS). So every
run_command / run_python call is prepared by Envs. If the user opted the
workspace into a container (Docker/Podman; asked once when it has a
devcontainer.json), the call runs there. Otherwise Envs stacks layers onto the
clean sandbox environment, first match winning:
- Installed: packages the model asked for with
install_packages, kept per workspace under<data>/envs/(Nix: onebuildEnv, a GC root, nixpkgs pinned; without Nix: apiximanifest of conda-forge packages). - Project venv: a
.venv/venvin the workspace (any OS). - Project environments (
Project): what the workspace declares itself, loaded once the user agreed (choices, asked once per workspace), then cached until its files change — aflake.nix/shell.nixdev shell (nix print-dev-env, shellHook included), a pixi project (pixi shell-hook --json), mise tools (mise env --json). - Support: what a package manager’s own CLI needs inside the sandbox, so the model
can also run
nix shell nixpkgs#foo --command …itself (store, daemon socket, config, a persistent eval cache), and Homebrew’sbin.
The last resort, system (Homebrew / winget, system-wide), always needs a person’s
approval. Failed output gets a hints line that names the one tool to call, because
small models follow an explicit next step far better than prose. Design and plans:
docs/environments.md.
Re-exports§
pub use command::CommandProvider;
Modules§
- choices
- What the user decided per workspace: load its project environment or not, run its commands in a container or not. A workspace is identified by its canonical path.
- command
- Environment providers plugins declare in their manifest (
environments): when the workspace has one of the provider’s files, run its command in the workspace (sandboxed, with network, may write the workspace) and read the environment it prints as JSON —{"PATH": "/x/bin:…", "NAME": "value"}(mise’s form) or{"environment_variables": {…}}(pixi’s). Asked once per workspace and cached until its files change, like byob’s own. - container
- Containers: a workspace can run its commands inside one long-lived Docker or Podman container instead of on this machine (opt-in per workspace; asked once when the workspace has a devcontainer.json).
- devcontainer
- What a workspace’s container is made from: its
.devcontainer/devcontainer.json(or.devcontainer.json), else the default image. - hints
- One-line “what to do next” for failed runs that lack a program or Python library. Small models recover far better from a concrete tool call than from general advice.
- nix
- Nix: the workspace’s own dev shell, packages installed on request, and a
nixCLI that works inside the sandbox. - pixi
- pixi as the
install_packagesbackend where there’s no Nix (Linux and macOS without it, Windows): conda-forge packages, per workspace, without root. - project
- Project environments from tools that print their environment as JSON, so they work the same on Linux, macOS and Windows:
- system
- The last resort: installing system-wide with Homebrew (macOS, Linuxbrew) or winget
(Windows), through
install_system_packages. Never the default — it changes the machine for every program and user, outside the workspace, and byob can’t undo it — so a person must approve every call (no grant or--auto-approvedoes), and only for packages the workspace installer (Nix, pixi) couldn’t provide, or where there is none.
Structs§
- Envs
- The package managers found on this machine, the per-workspace state they keep, and what the user decided per workspace.
- Found
- The package managers and tools found on this machine.
Found::detectlooks onPATH; tests build one by hand to hide what they don’t want used (e.g. Nix, to test the pixi installer on a machine that has both). - Installed
- The result of installing packages.
- Layer
- Changes a run gets:
PATHentries in front of the host’s, variables, and sandbox access.
Enums§
- Project
Mode - Whether project environments load (see
WORKSPACE_ENV).
Constants§
- KEEP_
VARS - Variables a layer must never set: the sandbox’s own home, temp and cache folders, and
what only makes sense inside a Nix build (mirrors
nix develop’s ignore list). - NATIVE_
PROVIDERS - byob’s own providers, by the id plugin manifests name them with (
environments[].native), andcontainer(dev containers, which aren’t anEnvProviderbut switch the same way). - WORKSPACE_
ENV - Override the per-workspace question:
BYOB_WORKSPACE_ENV=offnever loads a workspace’s own environment (installed packages and the Nix CLI still work),onloads it without asking. Unset (orask): ask once per workspace and remember the answer.
Traits§
- EnvProvider
- An environment a workspace declares in a project file (
flake.nix,pixi.toml,mise.toml, …): loaded once (slow, may download), then cached until its files change. - Runner
- Runs a sandboxed job for a provider (the tool’s own sandbox, with the support layer).
Functions§
- fnv64
- FNV-1a: a stable 64-bit hash for cache keys (std’s hasher may change between releases).
- join_
path PATHfor a run:prefixthen the host’s.- keep_
var - venv_
layer - A Python virtual environment in the workspace (
.venvorvenv): its scripts folder goes first onPATH, asactivatewould do.