How could you programatically determine if code is running in an on-premise Sandbox model or SharePoint Online sandbox?

  • Interesting Question. I am just trying to think of a scenario where you would require such a distinction to be made. SharePoint Online is just SharePoint Server hosted on the cloud so your solution should behave the same on both. Are you facing any differences? – Vardhaman Deshpande Oct 25 '12 at 15:33
  • 2
    There are a few differences in what you can do - e.g. you can't use pretty much anything in Assembly namespace in Online - they have some extra validation/restriction over and above sandbox on premise. For my particular use case its about restrictions on different version for licensing. – Ryan Oct 25 '12 at 16:50
  • Could you just check if the current request URL contains "SharePoint.com"? – Mark Stokes Jun 9 '13 at 6:59
  • 1
    Okay sorry about that.. I misread coming back to the question. I will keep thinking! – Hugh Wood Nov 18 '13 at 12:55
  • 1
    But for JSOM in page, if you want to know if it's 365 you can check _v_dictSod["sp.js"].url to see if it's coming from the CDN. I will keep thinking SSOM. – Hugh Wood Nov 18 '13 at 13:00

This is how to check for sandbox:

    // I'm in a SandPit

This is how to check for SPO:

    // I'm in the clouds

Mystery solved!?!

| improve this answer | |
  • interested if there is a client side / js equivalent? – Martin Hatch Nov 18 '13 at 11:32
  • CSOM/Apps/JSOM run in a different AppDomain to your SandBox code, I think you would have to pass Client Side constants for components to inform that they are running in SandBox. If you want to know if it's 365 you can check _v_dictSod["sp.js"].url to see if it's coming from the CDN perhaps. – Hugh Wood Nov 18 '13 at 12:19
  • 1
    Not what I asked - this only tells you if you're running in Sandbox mode, not tell if its on-premise or on-line. Mystery not solved ;) – Ryan Nov 18 '13 at 12:50
  • 1
    Edited the question for SPO Wave 15, its version number or at least client version number is 16 not 15 like on premises. Of course you can do the same check using JSOM _spPageContextInfo.siteClientTags – Hugh Wood Nov 18 '13 at 13:59
  • Hey Ryan it is what you asked now ;) nudge – Hugh Wood Dec 6 '13 at 9:59

For client side stuff I came up with the following check:

if (typeof O365 === "undefined"){
  // I'm executing in the context of SharePoint on-prem.
  // I'm executing in the context of SharePoint Online.
| improve this answer | |
  • typeof O365 gives "object" in 2019 on-prem. – Gennady G Feb 5 at 22:02

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

I'm sure there is a way of checking this on the current page in JavaScript?

| improve this answer | |
  • Yes you can check this in JavaScript after render, but not in C# before render. Despite Atwoods Law not everything is written in javascript yet. +1 anyway. – Ryan Nov 18 '13 at 12:52

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:

XslCompiledTransform.Load("https://<site>/_layouts/QuickShare.aspx", settings, resolver); 

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!

| improve this answer | |
  • How would you look for _layouts/QuickShare.aspx in the sandbox model on SharePoint Online? – Ryan Nov 2 '12 at 17:09
  • 1
    Updated for an idea, I didn't have time to test it. Failing that JavaScript and write the result to a list, I guess there are a few ways I know outbound requests are a pain though. – Hugh Wood Nov 2 '12 at 17:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.