Using the CLI Binary for Scripts and Agents
Overview
Scripts and agents call the CLI binary directly instead of the nvwb shell wrapper.
The binary is found at ~/.nvwb/bin/nvwb-cli on macOS and Linux, as well as in the WSL distribution on Windows.
The shell wrapper is a bash function that is only available in interactive shells that have sourced .bashrc.
A script or agent’s execution environment does not guarantee that.
The binary does not use activate, deactivate, open or close.
Those commands manage shell session state for interactive use through the nvwb wrapper.
Script and agent commands run in their own process, so they don’t inhereit session state.
Instead, you need to pass the location and project to the command explicitly using the -c and -p flags, as
well as setting the output flag like -o json.
Not all commands require the contect and project flag.
Not every command needs all three flags.
For example the list contexts command doesn’t require any flags, nor do the integration commands.
Others, for example list projects and list bases require a location flag with -c but not a project with -p.
The CLI does not change its output format when piped.
The default table output is identical whether stdout is a terminal or a pipe.
-o json is required for any command whose output you want to parse.
Key Concepts
Calling convention
Projects: ~/.nvwb/bin/nvwb-cli -c <context> -p <project-path> <command> [args] -o json.
Location but no project: ~/.nvwb/bin/nvwb-cli -c <context> <command> [args] -o json.
Targeting AI Workbench itself ~/.nvwb/bin/nvwb-cli <command> [args] -o json.
Context flag -c
Replaces activate when calling the binary.
Does not start the service on the location, and the location must already be running
Not needed for commands that do not target a specific location, such as list contexts or integration commands.
Project flag -p
Replaces open when calling the binary and takes the absolute path to the project directory on the location.
Not needed for commands that do not target a specific project, such as list projects or create project.
JSON output -o json
Returns structured JSON instead of styled table output. Required for parsing command results.
Calling Convention
Pass -c and -p where relevant, and -o json when you need to parse the output.
If you are scripting or using an agent from the Windows side, you can wrap them in a call to the proper WSL distribution.
Example: wsl -d NVIDIA-Workbench -u workbench -- /home/workbench/.nvwb/bin/nvwb-cli <arguments>
JSON Response Shapes
Every JSON response from the CLI is one of four shapes.
List and query commands return {"result": [...]}.
The result is always an array, even for a single item.
Access items with .result[] in jq.
The status command returns {"result": {...}}.
The result is a single object, not an array.
Access fields directly with .result.FieldName.
The create project and clone project commands return {"messages": [...]}.
Each message has message and detail fields.
The project path is embedded in the message string, not a dedicated field.
Use the --projectPath you passed to the command rather than parsing the message.
All errors return {"error": "...", "detail": "..."}.
This shape is consistent across every command. Exit code 1 accompanies every error response.
Project State Machine
Many commands require the project to be in a specific state before they succeed.
Check the project state with status before running commands that have preconditions.
Build states:
NO_BUILD— Build has never run or was reset.BUILDING— Build is in progress.BUILD_COMPLETE— Built and the project container is available.BUILD_ERROR— Last build failed.
Run states:
CONTAINER_NOT_CREATED— The project container does not exist.RUNNING— The project container is running.STOPPED— The project container exists but is stopped.
Preconditions by operation:
build— Any build state. Re-runs if already built.start <app>— Build state must beBUILD_COMPLETE. All sensitive environment variables must be configured.stop <app>— Run state must beRUNNING.add/removeenvironment variables, mounts, or secrets — Run state must beCONTAINER_NOT_CREATEDorSTOPPED.delete project— Run state must beCONTAINER_NOT_CREATEDorSTOPPED.
Check state before acting.
Useful Status Fields
The status command returns detailed project information.
Use jq to extract the fields you need.
Use the Project Path, Not the Name
Always identify projects by absolute path, not by name.
The registered project name comes from spec.yaml inside the repository, not from the directory name.
Cloning a project into --projectPath .../my-dir may register it under a completely different name.
The absolute path is stable and unambiguous.
Patterns
Check state, build, and start an application.
Iterate over all projects in a location.
Set a sensitive variable from stdin.
Create a project with a specific base environment.
Related Topics
- AI Workbench Command Line Interface (CLI) Reference - CLI command reference (command index, output formats, behavioral notes)
- Output Formats - JSON response shapes and output format details
- Project State Machine - Project state machine and preconditions
- Interactive CLI Use - Interactive CLI use
- Setting Up an Agent Skill - Setting up agent skills for the CLI