When you create Sandboxed Solutions, these features are capable of running either inside or outside of the sandbox. Because there are many restrictions on solutions running in the sandbox, you may want to detect if the current solution is running inside the sandbox. The following code will do it:
if (System.AppDomain.CurrentDomain.FriendlyName.Equals(
“Sandboxed Code Execution Partially Trusted Asp.net AppDomain”))
writer.Write(“You are in the Sandbox”);