Code in Sandboxed Solutions can execute as soon the ”Microsoft SharePoint Foundation Sandboxed Code Service” is started on some server somewhere in your Farm. Sandboxed Solutions are hosted withing a specialized gallery within a SiteCollections’ top level website. The provisioning of this gallery is controlled by the GLOBAL SiteDefinition meaning each SiteCollection you create (whether this Sandboxed Code service is running or not) will contain this gallery and by this enable SiteCollection Administrators to Upload and Activate Sandboxed Solutions.
So by default, when the Sandboxed Code Service is started, each SiteCollection whithin each WebApplication in your Farm is enabled to execute code in Sandboxed Solutions. Sometimes however you might want to disable the execution of code in Sandboxed Solutions on specific sitecollections while still allowing them to execute on other SiteCollections. There is no neat way to disable code execution from Sandboxed Solutions entirely on a specific SiteCollections. Maybe you’d expect to find a checkbox labeled “Disable Code Execution in Sandboxed Solutions” somewhere under Site Collection Settings in Central Admin but there isn’t.
This requirement could be achieved however by specifying a Quota Template and configure a specific SiteCollection to use it. Follow the steps below to specifiy a Quota Template effectively disabling Sandboxed code execution on a certain SiteCollection.
1. Open Central Administration
2. Browse to Application Management
3. Under Site Collections click “Specify Quota Templates”
4. Specify “Create a new quota template” and specify a name for it. Optionally you could start from an existing template here.
5. At the bottom of this page there’s a section with options to control Sandboxed Solutions called “Sandboxed Solutions With Code Limits”. Specify “0″ points in the TextBox labeled “Limit maximum usage per day to”
6. Click OK to save this template
7. Back on the Application Management Page, click “Configure Quotas and Locks”
8. On this Page, select the SiteCollection to apply the new quota template to
9. Under “Site Quota Information”, select the template just created
10. Click OK to save changes
Note that this will only block execution of custom code from within the Sandbox entirely. You are still able to provision declarative elements like List Instances for example to the Sandbox and use them without being blocked. I don’t think this is a problem however because otherwise the Site Collection administrator would have been able to create these kind of elements from within the browser or SharePoint designer anyway.
