Skip to main content
Run Python scripts inside the container on the specified box for test automation, hardware control, and data processing.

Syntax

Global Options

Arguments:
  • RUNNABLE - Python script file or directory to execute (required unless a process-management flag such as --kill, --kill-all, --reattach, --continue, or --console is used)
  • ARGS - Additional arguments passed to the script
Signal choices for --kill/--kill-all: SIGINT, SIGQUIT, SIGABRT, SIGKILL, SIGUSR1, SIGUSR2, SIGTERM, SIGSTOP

Basic Usage

Environment Variables

Setting Variables

Auto-Injected Variables

The following environment variables are automatically available inside your script:

File Downloads

Download files generated by your script after it completes:
Files are downloaded to the current working directory using the basename of the remote path. If a local file with the same name already exists, the command fails unless --allow-overwrite is set. Gzip-compressed files are automatically decompressed during download.

Detached Mode

Run scripts in the background without waiting for output:
In detached mode:
  • The command returns immediately after the script starts
  • No stdout/stderr is streamed back
  • The script continues running on the box
  • Use --kill to stop it later

Killing Running Scripts

Port Forwarding

Forward network ports from the box to your local machine:
Port format: SRC_PORT[:DST_PORT][/PROTOCOL]

Timeout

Limit script execution time:
When a script exceeds the timeout:
  • First, SIGTERM is sent (exit code 124)
  • If the script doesn’t exit, SIGKILL is sent (exit code 137)

Structured Output

Scripts running on the box can send structured data back to the CLI using the lager.core.output() function. This uses a dedicated output channel (file descriptor 3) separate from stdout/stderr.

Box-Side API

Available encoders: Structured output is printed to the CLI console as it arrives. Standard stdout and stderr are streamed separately in real time.

Module Includes

If your script depends on local modules, configure includes in a .lager file in your project:
The CLI searches up the directory tree for a .lager file, then zips the script along with all include directories before uploading to the box.
In test.py:

Additional Files

Upload extra files alongside your script:
Files are available in the same directory as your script on the box.

Exit Codes

Examples

Hardware Test Script Example

Notes

  • Use --env for script-specific configuration values
  • Use --passenv for secrets/tokens from your current shell
  • --download retrieves files only after script completion (not during)
  • Port forwarding syntax: SRC_PORT[:DST_PORT][/PROTOCOL]
  • After script execution, the hardware cache on the box is automatically cleared to release VISA connections
  • Output is streamed in real time via a multiplexed HTTP protocol with keepalive (20-second interval)

Installing Python packages

Scripts run inside the Lager Python container on the box. To install packages your scripts depend on, use the declarative lager box-config pip commands, which record the packages in the box config and rebuild the container so they persist across lager python runs and box updates.
See the Box Config reference for the full declarative provisioning workflow (pip/cargo/npm packages, apt, udev, mounts, env, and more).
The standalone lager pip command was removed and folded into lager box-config pip.