Declarative sandbox solutions are indeed supported in the SharePoint Online. Code-behind are not. Best option for this would be based on the detailed use case and scenario, but I'd approach this as follows.
- Create needed UI widget JavaScript file
- Upload file to centralized location - could be CDN or for example root site collection of particular tenant
- Use remote APIs to add this JavaScript file to UserCustomActions in site collection level -> it's activated in all sites in site collection
For deployment perspective would use PnP PowerShell, unless this should be automated. This way you can simply write scripts, which are pushing this to all site collections without requirement to go to UIs for activating sandbox solutions.
If you would have multiple files and would have to deploy stuff to each of the site collections, would look into creating PnP Remote Template for your configuration, but if it's only for associating JS file at site collection level, you can easily achieve this for example with Add-PnPJavaScriptLink (https://msdn.microsoft.com/en-us/pnp_powershell/addpnpjavascriptlink).
Note. This model ONLY works on classic mode, not in the modern sites. For modern sites, there's currently no supported way to do similar UI widgets. Work to enable that for them is on it's way, but can provide detailed schedules on that.
Like mentioned, obviously detailed scenario does have impact on the right design as well. How often this should be done, how it's integrated to new site collection creation, is it one time change etc.