Support run mode set by environment variable

Fixes #848 - let me know if issues