Library
REF 08 Cheat Sheet · Reference

Lifecycle scripts

Bash scripts on Linux, PowerShell on Windows. The filename encodes the target hostname. Track-level scripts run once per play; per-challenge scripts run around each challenge.

File naming & firing order Hostname-suffixed
track_scripts/setup-{hostname} Once, before the first challenge.
track_scripts/cleanup-{hostname} Once, after the lab ends. Required for costed external resources.
{NN-challenge}/setup-{hostname} Before this challenge starts.
{NN-challenge}/check-{hostname} When the learner clicks Check. exit 0 = pass, exit 1 = fail.
{NN-challenge}/solve-{hostname} When the learner clicks Skip. Must produce the same end state the check validates.
{NN-challenge}/cleanup-{hostname} After this challenge ends. Wipes per-challenge state.
Where work belongs Track vs per-challenge

Decision rule for which script gets the work.

Trap: putting one-time work in per-challenge setup wastes startup time on every challenge. Putting per-challenge state in track-level setup means later challenges can't reset it.
Bootstrap wait First line of every setup

Wait for the agent's bootstrap sentinel before any work.

until [ -f /opt/instruqt/bootstrap/host-bootstrap-completed ]; do sleep 1 done
Image-specific sentinel: on the cloud-client base image, wait for gcp-bootstrap-completed (in the same directory) instead. The standard sentinel is not written there.
Standard shebang Linux scripts

Top of every Linux lifecycle script.

#!/usr/bin/env bash is equally valid and resolves bash from PATH. #!/bin/sh only when POSIX is sufficient.

#!/bin/bash set -euo pipefail # (or set -euxo pipefail in setup # scripts for debug output)
Helper commands Image-dependent

Built-in agent helpers, available on Instruqt-published images.

fail-message "..." Render a learner-facing failure message in the UI.
set-status "..." Pass-side counterpart. Shows on success.
agent variable set/get Set or read variables that bridge into [[ Instruqt-Var ]] in body.
set-workdir /path Set default working directory for terminal tabs on this host.
Trap: raw upstream Docker images (ubuntu:22.04, python:3.11-slim) often don't ship the helpers. Guard with fail-message "..." || true.
Windows VM scripts PowerShell, no shebang

Lifecycle scripts on Windows VMs are PowerShell. No #! line.

Persistent processes register as Scheduled Tasks running at startup, then Restart-Computer -Force at the end of setup so the trigger fires.

Rename-Computer -NewName "win-1" ` -Force -PassThru Register-ScheduledTask -TaskName ... ` -Trigger (New-ScheduledTaskTrigger ` -AtStartup) ... Restart-Computer -Force
Notes