Run Script After Sandbox Creation and Refresh

To make your sandbox environment business ready, automate data manipulation or business logic tasks.

At sandbox creation, specify a single Apex class to perform the tasks. This class executes every time the sandbox is copied.Lightning interface of sandbox post-copy script specification

Create an Apex class that implements SandboxPostCopy and specify the class here. For example, the following Apex class simply reports the three contexts available in SandboxPostCopy: your organization ID, sandbox ID, and sandbox name:
global class HelloWorld implements SandboxPostCopy {
  global void runApexClass(SandboxContext context) {
      System.debug('Hello Tester Pester ' + context.organizationId()
           + ' ' + context.sandboxId() + context.sandboxName());