The classes .Routine, .Method, and .Package have a method setSecurityManager.
Make the "setSecurityManager" method protected so that its use can be supervised by security managers. Otherwise a code block can remove an active security manager, without it noticing this.
If protected, a security manager can itself decide whether a change/removal is acceptable or not, or ignored.
Anonymous
The "setSecurityManager" methods are already protected.