Challenge scripts

Add setup, check, solve, and cleanup scripts to your challenges


Challenge scripts can be written in whatever scripting language you like, such as Bash or Python. There are four types of challenge scripts:

  • Setup: Automate commands prior to the challenge starting

  • Check: Determine if users completed specific tasks, runs when Check is clicked

  • Solve: Automate users work, runs when Skip is clicked

  • Cleanup: Automate commands once a challenge is completed

Add challenge scripts

Challenge scripts can be added using the Web UI or the Instruqt CLI.

  1. From a Track dashboard page, click the challenge you wish to add a script to.

  2. From the top navigation bar, click Scripts.

  3. Determine which host in the sandbox you want the script to run on.

  4. Add a script to the host's setup, check, solve, or cleanup script file.

Setup scripts

Use challenge setup scripts to:

  • Create files that are necessary for the challenge.

  • Send analytics events.


The following example creates an empty file and a pre-filled file that are available in a challenge:

set -euxo pipefail

# create an empty file called challenge.txt
echo > challenge.txt

# create a pre-filled file called
echo " # How to create a challenge setup script  " >

Check scripts

Use challenge check scripts to:

  • Check if a learner solved a challenge correctly.

  • Provide a fail message and a hint if the learner failed to solve the challenge.


The following example checks if the learner created a directory called instruqt. If the learner created the directory, the script returns a success message, and Instruqt continues with the next challenge. If the learner has not created the directory, the script returns a fail message with a hint to the learner, and Instruqt stays at the current challenge.

set -euxo pipefail

echo "Checking if the directory instruqt exists."

if [ -d /root/instruqt ]
    echo "The directory instruqt exists"
    fail-message "There is no directory named instruqt, did you create it?"

Alternatively, the following example uses an exit code to process the challenge check. If the check fails, line 5 sends a feedback message prefixed with FAIL: to the stdout and line 6 sets the exit code to 1, which marks the script as unsuccessful:


echo "Checking the solution of the challenge"
  echo "FAIL: Your challenge failed because of [REASON]"
  exit 1

Solve scripts

A challenge solve script solves the current challenge to allow the learner to skip ahead if you enabled skipping. Challenge solve scripts run in the following scenarios:

  • When a learner skips a challenge.

  • When you issue the instruqt track test command in Instruqt CLI to test a track.


The following example solves a challenge by creating a directory called instruqt:

set -euxo pipefail

mkdir -p /root/instruqt

Cleanup scripts

A challenge cleanup script runs after the learner completes a challenge before Instruqt sets up the next challenge.

Use challenge cleanup scripts to reset script artifacts for the next challenge.


The following example resets an earlier file that the learner changed:

set -euxo pipefail

# overwrite with an empty file 
echo > challenge.txt

Last updated