This is the complete technical reference for Moodle Playground blueprint files. For a hands-on introduction and step-by-step walkthrough, see the Overview. For ready-to-run files you can open immediately, see the Examples. Version selection and Docker portability are covered in Runtime & Versions. The machine-readable JSON Schema is published atDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/ateeducacion/moodle-playground/llms.txt
Use this file to discover all available pages before exploring further.
blueprint-schema.json — add it to your editor for autocomplete and inline validation.
A blueprint is a JSON document describing the desired state of an instance at boot. Steps run sequentially in array order.
Top-level fields
| Field | Type | Required | Description |
|---|---|---|---|
steps | array | yes | Ordered list of step objects. Each object must include a step name string. |
constants | object | no | {{KEY}} → string map. Every placeholder is substituted deeply across all fields before steps run. |
resources | object | no | Named file descriptors referenced as @name from step fields. |
runtime | object | no | Boot-time config.php settings: debug (0/5/15/32767) and debugdisplay (0/1). |
phpConstants | object | no | PHP constants defined in config.php before lib/setup.php. Name → boolean / string / number. |
landingPage | string | no | Path opened after boot. Must start with /. |
preferredVersions | object | no | { "php": "8.3", "moodle": "5.0" } — preferred runtime, subject to compatibility fallback. |
$schema | string | no | Informational schema reference for editor validation. |
Constants
constants defines {{KEY}} placeholders that are replaced deeply in every string value before any step executes.
{{REPO}}, {{OWNER}}, {{REF}} / {{BRANCH}} are derived from the repo, owner, and branch (alias ref) URL parameters and merged over the blueprint’s own constants. This lets a committed blueprint target the branch it is currently previewing without hardcoding the branch name. See URL parameters.
PHP constants
phpConstants defines PHP constants in the booted Moodle’s config.php, before require_once(lib/setup.php), so they are available on every request. Each entry is emitted as a guarded define():
config.php:
^[A-Z_][A-Z0-9_]*$ — names that do not match are silently skipped. This lets a plugin’s own blueprint enable plugin-specific configuration without the playground engine needing to know any plugin-specific details. For example, mod_exelearning declares "phpConstants": { "EXELEARNING_UNSAFE_LEGACY_IFRAME": true } so its demo renders the content iframe same-origin.
Resources
A resource is a named file descriptor with exactly one source key. Reference it from any step with the string"@name", or inline the descriptor directly in the step field.
| Key | Value |
|---|---|
url | Fetch over HTTP(S). ~30 s timeout, ~50 MB cap. |
base64 | Inline base64-encoded data. |
data-url | A data: URI. |
bundled | Path relative to the app bundle. |
vfs | Path already present in the runtime filesystem. |
literal | Inline string or object value. |
Steps
Legend:
- (HTTP) — runs over an HTTP request (preserves session cookies).
- (marker) — records options for boot; does no runtime work itself.
- (non-fatal) — reports a failure but does not abort the remaining steps.
- Batch steps — accept an array under the named field and process each entry.
- All other steps abort the blueprint on error.
Install and auth
installMoodle (marker)
Records install options consumed at boot time. The actual installation is performed by bootstrap.js before steps run; this step passes configuration into that process.
Installation options object.
setAdminAccount
Updates the site admin account. All fields are optional.
New password for the admin.
New email address.
Admin first name.
Admin last name.
login (HTTP)
Starts an authenticated session. Subsequent HTTP steps (e.g. request, runPhpScript) will use this session’s cookies.
Username to log in as. Default:
admin.Configuration
setConfig
Writes a single Moodle configuration value to mdl_config or mdl_config_plugins.
The config setting name (e.g.
enablebadges, country).The value to set. Default:
"".Plugin name for plugin-specific settings (e.g.
theme_boost). Omit for core settings.setConfigs (batch)
Sets multiple config values in one step.
Array of
{ "name": "...", "value": "...", "plugin": "..." } objects.setTheme
Activates a Moodle theme by directory name.
Theme directory name, e.g.
boost, moove, classic.setLandingPage (marker)
Sets the page that opens after boot. Overrides the top-level landingPage field.
Site-relative path, must start with
/. E.g. /my/, /course/index.php.Users
createUser
Creates a Moodle user account.
The login username.
Account password. Default:
password.Email address. Default:
<username>@example.com.First name. Default: the username value.
Last name. Default:
User.createUsers (batch)
Creates multiple users in one step.
Array of user objects, each with the same fields as
createUser.Categories
createCategory
Creates a course category.
Category display name.
Category description (HTML or plain text).
Name of an existing parent category. Omit for a top-level category.
createCategories (batch)
Array of category objects.
Courses
createCourse
Creates a Moodle course.
Full course name displayed in headings.
Short name — the stable identifier used to reference this course in other steps.
Category name. Defaults to the top category if omitted.
Course summary (HTML or plain text).
Course format. Default:
topics.Number of sections. Default:
5.createCourses (batch)
Array of course objects.
createSection
Creates a named section inside an existing course.
Course shortname.
Section display name.
Section position (0-indexed). Default:
0.createSections (batch)
Array of section objects.
Enrolment
enrolUser
Enrols a user in a course with a given role.
Username of the account to enrol.
Course shortname.
Moodle role shortname. Default:
student. Common values: student, editingteacher, teacher, manager.enrolUsers (batch)
Array of
{ "username": "...", "course": "...", "role": "..." } objects.Modules
addModule
Adds an activity or resource module to a course section. Any extra field beyond the documented ones is written directly to the module’s database record, so activity-specific settings can be set here.
Activity type name, e.g.
label, assign, folder, page, quiz, board.Course shortname.
Section number (0-indexed). Default:
0.Activity name shown in the course page.
Activity description / introductory HTML.
Array of file attachments. Each entry requires
filename and data (resource descriptor); optional: filearea (default content), itemid (default 0), filepath (default /).Third-party modules must be installed with
installMoodlePlugin before addModule can reference them.Course restore
restoreCourse (non-fatal)
Restores a Moodle course from a .mbz backup file. This step is non-fatal — a failure is logged but does not stop remaining steps.
Direct URL to the
.mbz file. Takes precedence over path and data.Filesystem path to the
.mbz file inside the runtime. Takes precedence over data.Resource descriptor or
@name reference. Used if neither url nor path is given.Target category name. Auto-created if it does not exist.
Whether to auto-create the target category. Default:
true.Override the course full name from the backup.
Override the course short name from the backup.
Whether the restored course is visible to students. Default:
true.Roles
createRole
Creates a custom Moodle role.
Unique machine-readable role identifier.
Human-readable role name.
Role description.
Base archetype to derive default permissions from (e.g.
editingteacher, student).Reset capabilities to the archetype’s defaults before applying overrides.
List of context levels (names or integers) where the role can be assigned.
Map of capability name →
allow / prevent / prohibit / inherit.Role shortnames this role may assign.
Role shortnames this role may override.
Role shortnames this role may switch to.
Role shortnames this role may view.
createRoles (batch)
Array of role objects, a
@resource reference, or a URL resolving to a JSON array.importRolePreset
Imports a role from a Moodle XML role-preset file using Moodle’s built-in parser.
Inline role-preset XML string.
@name reference or resource descriptor resolving to XML.importRoles (batch)
Array of XML references:
@name, raw XML string, { "xml": "..." }, or a resource descriptor.Scales
createScale
Creates a grading scale.
Scale display name.
Scale values from lowest to highest — as an array (
["Not yet", "Competent"]) or comma-separated string.Scale description.
Course shortname for a course-level scale. Omit for a site-wide scale.
createScales (batch)
Array of scale objects, a
@resource reference, a URL, or the { "format": "moodle-scale-export", "scales": [...] } export envelope.Cohorts
createCohort
Creates a site cohort (system-wide group).
Cohort display name.
Unique idnumber used as an idempotency key and for external sync.
Cohort description.
Whether the cohort is visible in the UI. Default:
true.Array of existing usernames to add as members on creation.
createCohorts (batch)
Array of cohort objects, a
@resource reference, or a URL.Plugins and themes
installMoodlePlugin
Downloads and installs a Moodle plugin from a GitHub archive ZIP URL.
GitHub archive ZIP URL, e.g.
https://github.com/org/moodle-mod_board/archive/refs/heads/MOODLE_405_STABLE.zip.Override the detected plugin type (e.g.
mod, block, local). Auto-detected from the moodle-TYPE_NAME repo-name convention.Override the detected plugin name. Auto-detected from the repo name.
installTheme
Downloads and installs a Moodle theme. Files are placed in theme/<name>/ but the theme is not activated — pair with setTheme to activate it.
GitHub archive ZIP URL.
Override the detected theme name.
Languages
installLanguagePack (non-fatal)
Downloads and installs a Moodle language pack. This step is non-fatal — a download failure is logged but does not abort the blueprint.
A single language code (e.g.
es, fr). Matches ^[a-z][a-z0-9_]*$.A comma-separated string or array of language codes.
Alias for
language / languages.Set this language as the site default. Default:
false.File-backed config settings
These steps register a file with Moodle’s File API and point a config setting at it. This is required for logos, favicons, and theme images —setConfig alone cannot do this because those settings reference file record IDs, not raw paths.
setConfigFile
Plugin or component name (e.g.
theme_boost, core_admin).Config setting name that will be set to the file’s item ID.
Filename to store in the File API (e.g.
logo.png).Resource descriptor or
@name reference to the file contents.File area name. Default: same as
name.File API item ID. Default:
0.File path in the File API. Default:
/.Replace an existing file at the same path. Default:
true.Write the item ID to the config setting. Default:
true.Purge Moodle caches after storing the file. Default:
false.Author metadata for the File API record.
License string for the File API record.
Source URL metadata for the File API record.
User ID to own the file. Default: site admin ID.
setConfigFiles (batch)
Stores multiple files under a single component+setting combination.
Plugin or component name.
Config setting name.
Non-empty array of
{ "filename": "...", "data": ... } objects. Top-level optional fields act as defaults; the config value is set to the first stored file’s item ID.Filesystem
mkdir
Creates a directory (recursively, like mkdir -p).
Absolute path in the WASM filesystem.
rmdir
Removes a directory.
Absolute path to remove.
Remove contents recursively. Default:
false.writeFile
Writes data to a file, creating parent directories as needed.
Absolute path of the file to write.
Inline string,
@reference, or resource descriptor.writeFiles (batch)
Array of
{ "path": "...", "data": ... } objects.copyFile
Copies a file within the WASM filesystem.
Source path.
Destination path.
moveFile
Moves (renames) a file within the WASM filesystem.
Source path.
Destination path.
deleteFile
Deletes a single file. Idempotent — a missing path is skipped without error.
Absolute path of the file to delete.
deleteFiles (batch)
Array of string paths or
{ "path": "..." } objects.unzip
Extracts a ZIP archive into a destination directory.
Resource descriptor or
@name reference to the ZIP file.Absolute path to extract into. Also accepted as
path.Requests and code
request (HTTP)
Makes an HTTP request to the running Moodle site. Useful for triggering cron, flushing caches, or calling web services.
URL to request. Default: the site root.
HTTP method. Default:
GET.HTTP request headers as a key-value map.
Request body (for POST/PUT).
Abort the blueprint if the response status is ≥ 400. Default:
true.runPhpCode
Executes arbitrary PHP code in CLI mode (CLI_SCRIPT). The <?php opening tag is optional.
PHP code to execute.
runPhpScript (HTTP)
Writes PHP code to a temporary file and executes it over HTTP (session cookies are available).
PHP code to execute.
Abort on HTTP status ≥ 400. Default:
true.PR overlay
applyPrOverlay
Fetches changed files from a GitHub pull request or branch comparison and overlays them on the running Moodle filesystem, then optionally runs the upgrade script and purges caches.
Pre-resolved file manifest (skips GitHub API). Takes highest precedence.
GitHub repository in
owner/repo format (e.g. moodle/moodle).Pull request number. Used with
repo to resolve files from a PR.Base branch for a branch comparison. Default:
main. Used with repo + head.Head branch or commit SHA for a branch comparison. Used with
repo + base.Override the base commit ref used for diff resolution.
Whether to run
admin/cli/upgrade.php. One of off / on / auto. Default: auto (best-effort, non-fatal).Filesystem root to overlay files into. Default:
/www/moodle.HTTP proxy URL for GitHub API requests.
Abort if the PR touches more files than this. Default:
200.Skip individual files larger than this (bytes). Default: 5 MiB.
Purge Moodle caches after applying the overlay. Default:
true.purgeMoodleCaches
Resets all Moodle caches and the component registry. Run automatically by applyPrOverlay.
Execution model
Steps in a blueprint run sequentially in array order. The execution model distinguishes four categories:- CLI steps — the majority of steps; run PHP in
CLI_SCRIPTmode. A non-zero exit code aborts the blueprint. - HTTP steps (
login,request,runPhpScript) — run over an HTTP request against the running Moodle site, allowing session cookies to persist across calls. - Marker steps (
installMoodle,setLandingPage) — do no runtime work; they record configuration consumed during or after the boot sequence. - Non-fatal steps (
restoreCourse,installLanguagePack) — report failures to the console but continue with the next step. ForapplyPrOverlay, individual oversized files are skipped and the upgrade/cache-purge phases are best-effort, but manifest resolution failures and exceedingmaxFilesstill abort.
createRole, createScale, createCohort, and importRoles generators silently skip references to capabilities, roles, or users that do not exist at runtime, but a missing required field or a PHP error still aborts the blueprint.
For complete, working examples see the Examples page.