set environment script improvements

This improves the way set environment script works, also add a feature to soude the agent environment if possible