The approved solution is to create a SharePoint Framework (SPFx) webpart to run the code. While there is a learning curce to SPFx, the result is code that is safer and ensures admin oversight (capability.) IF you have code that is already running in a SEWP, putting that into SPFx should not be too difficult.
I hope this answers your question. If so, please mark my response as the approved answer. Thanks.