In the SharePoint admin center, you can choose to disallow users to run custom script on OneDrive (referred to as "personal site") or on all classic team sites they create. After you disable custom script in the SharePoint admin center, it can take up to 24 hours for the change to take effect.
To disallow custom script on other SharePoint site, you should run following PowerShell in the SharePoint Online Management Shell.
#Config Parameters
$AdminSiteURL="https://crescent-admin.sharepoint.com"
$SiteURL="https://crescent.sharepoint.com"
#Get Credentials to connect
$Cred = Get-Credential
#Connect to SharePoint Online Tenant Admin
Connect-SPOService -URL $AdminSiteURL -Credential $Cred
#sharepoint online enable custom scripts powershell - Disable DenyAddAndCustomizePages Flag
Set-SPOSite $SiteURL -DenyAddAndCustomizePages $True
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.