How could you programatically determine if code is running in an on-premise Sandbox model or SharePoint Online sandbox?
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!