Implement script env support. Fixes #579

Implement script env support. Fixes #579