Use N/runtime module.
if (runtime.envType == runtime.EnvType.SANDBOX) {
log.debug("the script is running in sandbox environment")
}
if (runtime.envType == runtime.EnvType.PRODUCTION) {
log.debug("the script is running in production environment")
}