Skip to content

Lifecycle Scripts

Lifecycle scripts build, configure, and grade your sandbox. There are four: build.sh, setup.sh, answer.sh, and score.sh.

All scripts must begin with #!/usr/bin/env bashp — not #!/bin/bash. The bashp preprocessor inlines library functions like install::apt_packages and scoring::check before execution.

When each script runs

Script When What to put here
build.sh Once, at image build time Package installs, tool downloads, static files
setup.sh Every time the sandbox starts Service starts, runtime configuration
answer.sh During testing only The steps a perfect candidate would take
score.sh When the candidate submits Pass/fail checks followed by scoring::report

build.sh

Runs once when the VM image is built. Results are baked into the image, so sandboxes start fast.

#!/usr/bin/env bashp
set -ex

install::apt_packages vim git curl

Warning

Do not start services in build.sh. Services started here are baked into the image. Use setup.sh instead.

setup.sh

Runs every time a sandbox instance starts. Use it to start services and prepare the candidate's environment.

#!/usr/bin/env bashp
set -ex

systemctl enable --now nginx

answer.sh

Applies the reference solution. Never runs in production — only when you run sandbox answer or sandbox test locally. Write it as the exact steps a correct candidate would take.

#!/usr/bin/env bashp
set -ex

echo "bar" > /tmp/foo

score.sh

Checks the candidate's work. Each check is a function that returns 0 for pass or non-zero for fail. Run checks with scoring::check and end the script with scoring::report.

#!/usr/bin/env bashp
set -e

check_file_exists() {
    test -f /tmp/foo
}

check_file_content() {
    grep -q "bar" /tmp/foo
}

scoring::check check_file_exists
scoring::check check_file_content
scoring::report

The number of scoring::check calls must equal total_check_count in metadata.yaml.

Test the full lifecycle

Run all four scripts end-to-end with one command:

sandbox test

This passes when scoring returns zero checks before answer.sh runs, and full marks after. If it fails, the output tells you which check did not pass and at which stage.