OpenRecoveryScript is an open scripting engine that any recovery and any app can use to as an API between app and recovery. TWRP versions and higher can also use OpenRecoveryScript commands via adb shell command.  This engine allows an app to tell a recovery to install zips, perform backups, etc.  Below is documentation of the API:

For apps, the script file needs to be: /cache/recovery/openrecoveryscript

For the command line, do adb shell twrp then enter each command one at a time. For instance:
adb shell twrp wipe cache

Each line represents a different command. Commands are executed in order, top to bottom. If an error occurs, the script will stop executing. Commands must be lower case. If a parameter is needed, the parameter will follow the command with a space. You have the following commands and parameters to work with:

install /sdcard/path/ (note, if you don't supply a leading slash, TWRP will use "relative paths" instead of absolute paths which is handy on dual storage devices and devices where the path to storage in the ROM isn't the same as the path in recovery -- relative paths available in TWRP 2.2 and later only)
wipe cache
backup SDCR123BAEOM foldername
-S = System
-D = Data
-C = Cache
-R = Recovery
-1 = special partition 1
-2 = special partition 2
-3 = special partition 3
-B = Boot
-A = Android secure
-E = SD-Ext
-O = use compression
-M = do not create MD5
-foldername is optional and is just the final folder in the full TWRP path
restore foldername SDCR123BAEM
-foldername is fully qualified with /sdcard/TWRP etc.
-partitions are optional, if nothing is set, then all partitions will be restored
-setting a flag for a partition that doesn't exist in the backup will not throw an error
-flags are the same as backup, there is no O for compression in restore
mount path
unmount path
set variable value
-use this to change variables that are in the TWRP settings file
mkdir /folder1/folder2/folder3
-fully recursive, will create all folders needed in the full path
cmd command line command with any parameters
print whatever you want to have displayed (added in TWRP 2.2 and later)

Here are some examples:
install /sdcard/
wipe data
wipe cache
wipe dalvik
backup SDBOM (will backup system, data, and boot and use compression and skip MD5 generation)
backup SDBOM myrom (backups the same as above in a folder called myrom)
restore /sdcard/TWRP/BACKUPS/*serialno*/myrom (would restore all partitions found in myrom)
restore /sdcard/TWRP/BACKUPS/*serialno*/myrom DM (would restore only the data partition in myrom and skip MD5 checking)
mount system
unmount system
set tw_signed_zip_verify 0 (would turn off zip verification)
set tw_time_zone CST6;CDT (would set the time zone to central time)
mkdir /sdcard/folder1/folder2 (would potentially create 2 folders on your sdcard if they don't already exist)
cmd chmod 755 /system/bin/htcdumlock (obviously you need to have system mounted for this to work)
cmd htcdumlock restore (this would restore the original boot if the user is using htcdumlock)

In addition to the above script commands, the command line also supports the get command which will display the current value of any TWRP variable. You may use adb shell twrp get tw_page_done for example. You can also push an OpenRecoveryScript script file to the device and run it after TWRP boots with adb shell twrp runscript /sdcard/script