We have been working with Salesforce for awhile now and I’ve appreciated the fact that when they create a “Sandbox” for you, the field IsSandbox on the Organization object is set to true. I don’t have to do anything and can use it in code to do this or that depending on the environment. And I can’t change that field.
It would be nice if there is a way that the App Server could have a flag that the Session object could pick up that would indicate what Database environment it is connected to. I get that we could probably make our flag somewhere in the DB and set that when we reload a DB but I would rather set it at the App Server level in case someone forgets to reset it in the DB.