What is the Groovy sandbox and script approval in Jenkins?
AdvancedConceptJenkins
Answer
Pipeline Groovy runs in a sandbox that only allows a whitelist of safe methods. When a Jenkinsfile calls something outside the whitelist, the build fails with RejectedAccessException: Scripts not permitted to use method ... and an administrator must approve the signature under Manage Jenkins > In-process Script Approval.
Trusted shared libraries (configured globally, not "load implicitly from SCM for untrusted users") run outside the sandbox, which is why only admins should be able to change them. Approving dangerous signatures like Runtime.exec effectively gives the pipeline author control of the controller JVM.
More on Jenkins
What is Jenkins and how is its architecture organised?BeginnerWhat are executors, nodes and labels in Jenkins?IntermediateWhy should you not run builds on the Jenkins controller?BeginnerHow do inbound (JNLP/WebSocket) and SSH agents connect to the controller?IntermediateWhat is a Jenkinsfile and where does it live?BeginnerDeclarative versus Scripted Pipeline: what are the differences?Intermediate