How could you programatically determine if code is running in an on-premise Sandbox model or SharePoint Online sandbox?
This is how to check for sandbox:
This is how to check for SPO:
How about checking the current page script files .. a whole bunch of them come from cdn.sharepointonline.com.
e.g. https://cdn.sharepointonline.com/7085/_layouts/15/init.js?rev=T%2B51qvNtDMdb8GaqPbzXag%3D%3D https://cdn.sharepointonline.com/7085/_layouts/15/1033/initstrings.js?rev=hxd8ClaHhdv0iS7vbodfQg%3D%3D https://cdn.sharepointonline.com/7085/_layouts/15/1033/strings.js?rev=23IMQCq1f6scE85dxNy2Xg%3D%3D
A good comparison of them is here:
As for checking the environment I would look for the _layouts/QuickShare.aspx
Since it is a SharePoint 365 only feature.
[update] Something like:
Should work right maybe not with outbound requests blocked? Okay it's messy but I can't think of another way that you can load a remote file on 365 at the moment.
But you could do something to throw it at the client side to update a local list?
[note] When the new version comes out, you will be able to do things like this much easier!