SharePoint 2010 Sandbox Solutions


Sandbox solution: Deployed directly into a Site Collection (Solution Gallery).
Farm Solution: Deployed at Farm level at _layouts or GAC.


A site collection administrator, or another user with sufficient permissions, uploads the solution package to a specialized library—the solution gallery—in the root site of the site collection.
Sandboxed solutions are packaged as SharePoint solution package (WSP) files that contain assemblies, other non-compiled components, and an XML manifest file.

Uses and benefits of sandboxed solutions:

There are two common scenarios where it is appropriate to use sandboxed solutions:
  • When an organization wants to run code for employees on a production SharePoint Server site, and that code has not been rigorously reviewed and tested.
  • When a hoster wants to let the owners of hosted SharePoint Server sites upload and run custom code.
The main benefits of using sandboxed solutions are as follows:
  • Sandboxed solutions can be added to a production SharePoint Server environment without the risk of affecting processes outside the sandbox.
  • Site collection administrators can deploy sandboxed solutions. This frees farm administrators from this task.
  • Scalability and flexibility are increased because sandboxes run in a separate process that can be restricted by quotas, and their effect on the farm can be monitored.
  • A solution does not have to be modified or recompiled if it is moved from a sandbox to running directly on the farm.
  • Technically speaking SharePoint solutions run in separate worker processes and not in w3wp.exe. So It doesn't require IIS Reset or Application Pool Recycling.


What Can I Do with Sandboxed Solutions?
Some common SharePoint development scenarios.This is not an exhaustive list; however, it serves to give you a feel for the types of scenarios that you can implement with a Sandbox solution.
Scenario Sandbox Hybrid Full-Trust
Create a Web Part that aggregates data from multiple SharePoint lists within the same site collection. * Ff798382.46b998ae-a202-410a-bd50-f7178ffdfe4d(en-us,PandP.10).png Ff798382.3ade5e73-5d5b-495c-a5ab-689032ec3f7a(en-us,PandP.10).png Ff798382.2a78007a-88d5-4fe8-8932-88138d31015d(en-us,PandP.10).png
Create a Web Part that aggregates data from multiple SharePoint lists from different site collections within the same SharePoint farm.
Ff798382.ff4af543-ef36-4941-a937-5589c199b23a(en-us,PandP.10).png Ff798382.48d8d5fc-2981-4469-9a76-16c728ff0b4c(en-us,PandP.10).png
Create a Web Part that aggregates data from multiple SharePoint lists from different site collections from different SharePoint farms.
Ff798382.3ec7c268-3ad6-415d-8173-a9cd92eb283a(en-us,PandP.10).png Ff798382.03d977bb-83a0-49c1-a59d-f6d09ff30e9b(en-us,PandP.10).png
Create a Web Part that displays data from an external list.
Ff798382.9e21df6d-b385-499c-9274-10889d512f5f(en-us,PandP.10).png Ff798382.d0c14e08-6879-4e5a-b57b-2c094ac99146(en-us,PandP.10).png
Create a Web Part that interacts with a Web service or a Windows Communication Foundation (WCF) service.
Ff798382.73da4ecb-ec82-463b-9180-1da4564c01fa(en-us,PandP.10).png Ff798382.c2c9ae17-6795-476d-9dd8-f9f0c97cd51a(en-us,PandP.10).png
Create a workflow in SharePoint designer. Ff798382.22273bdd-d15e-4cab-b3b8-d07c58753958(en-us,PandP.10).png Ff798382.4205369d-7455-4c4c-86d5-9329d140ebab(en-us,PandP.10).png Ff798382.eb816d1d-4f9f-4cc4-bde4-2b5f408426ce(en-us,PandP.10).png
Create a sandbox workflow action (a method call). Ff798382.6952c1e4-c502-442e-933c-3f608f5fb5dc(en-us,PandP.10).png

Create a full-trust workflow activity.
Ff798382.170a02ae-029b-4302-b0bf-71039d910271(en-us,PandP.10).png Ff798382.3126ec2b-fd04-471c-a6d1-764695525e8c(en-us,PandP.10).png
Create a workflow in SharePoint designer that uses a full-trust custom coded workflow activity.
Ff798382.34e62d55-1add-4893-88bc-8ac8445a3f7e(en-us,PandP.10).png Ff798382.7926bd64-7f37-4433-8c42-4e1204af633e(en-us,PandP.10).png
Create a fully coded workflow.

Ff798382.163b6927-6b89-48f5-b275-a3173d840694(en-us,PandP.10).png
Deploy a new list definition. Ff798382.6bc5fa33-0495-4303-b7be-88a232d0e7e9(en-us,PandP.10).png Ff798382.64ae8636-e14c-48fd-b4bd-e4c43249100f(en-us,PandP.10).png Ff798382.8f5fa059-4bcb-4af6-b749-ee1ea97eaa43(en-us,PandP.10).png
Deploy a new list definition with list item event receivers. Ff798382.ba8349f2-e6d1-4b88-a617-edd7f96bff1b(en-us,PandP.10).png Ff798382.41b63bc9-a1a8-4646-9adb-0a048e47fd3d(en-us,PandP.10).png Ff798382.65319dda-6b32-41f8-a849-8f7d15a3d4a1(en-us,PandP.10).png
Deploy a list definition with list event receivers. Ff798382.e7ca0931-ec51-44af-879d-edaca94c39d4(en-us,PandP.10).png Ff798382.ab22c3a7-3ed6-4296-b533-530467aa82fc(en-us,PandP.10).png Ff798382.e57dfff5-07e6-47d6-8cc5-bcc46a3a4030(en-us,PandP.10).png
Deploy a site definition. Ff798382.317bd1bc-1e21-40b3-8139-adad48442abd(en-us,PandP.10).png Ff798382.262483b9-14fa-4fd5-ab31-d26a3104568b(en-us,PandP.10).png Ff798382.dc9639ef-08d7-421e-8367-a5e1fbfc1b7e(en-us,PandP.10).png
Create a content type. Ff798382.11f49b46-4221-4b16-ae07-8dd6f2dd23a5(en-us,PandP.10).png
Ff798382.730b2e88-e12c-4d91-8f88-fea667883cad(en-us,PandP.10).png
Create an external content type.**

Ff798382.c9a77d76-f409-4c29-bcc4-822523b7d86d(en-us,PandP.10).png
Create a new ribbon element. Ff798382.95ddb816-d38c-4da6-94be-bc280afa147b(en-us,PandP.10).png Ff798382.ef81c3dd-f3ed-427c-bba3-4a9b0292daa0(en-us,PandP.10).png Ff798382.03ed3d75-f3b5-4733-95e5-1dea0b63e3b7(en-us,PandP.10).png
Create a new Site Actions menu item. Ff798382.b718bf37-e9c5-4e69-86ff-fa599f35d067(en-us,PandP.10).png Ff798382.f791d4bf-1eb8-41c1-9a8b-d896f89bfe13(en-us,PandP.10).png Ff798382.edcc1d1d-2e9c-4fc9-ac08-5c36cd0f2b7a(en-us,PandP.10).png
Create an instance of a SharePoint list. Ff798382.1b19d6ce-0ff7-4653-8be2-26055cd67755(en-us,PandP.10).png Ff798382.e2a27237-9759-4698-87b5-e15cc6fbe7d5(en-us,PandP.10).png Ff798382.a6823927-ce3b-4a60-b527-6b65495db43a(en-us,PandP.10).png
Programmatically create a SharePoint subsite. Ff798382.765fe86b-e485-4658-895f-2c64669bfb90(en-us,PandP.10).png Ff798382.e8834a64-197e-4f93-beed-a0c436919f3c(en-us,PandP.10).png Ff798382.e32aa134-2b04-4ea4-979d-630b4ae059ba(en-us,PandP.10).png
Bind a content type to the home page of a SharePoint subsite.
Ff798382.36146ede-7ec3-4ac4-93fc-88c4eba2098f(en-us,PandP.10).png Ff798382.9ce6dbfc-28fb-4e00-b4a4-dde04bb6eafd(en-us,PandP.10).png
Deploy a new application page.

Ff798382.ca1f9dc5-d4cb-4efa-ae44-f053fa10a822(en-us,PandP.10).png
Create a timer job.

Ff798382.fd67a3b8-7ab3-45dd-9b18-1763c4cfede4(en-us,PandP.10).png
Create a service application.

Ff798382.3584eff9-9520-4992-a724-448c7f8614ff(en-us,PandP.10).png

*The Visual Web Part supplied with Visual Studio 2010 will not run in the sandbox. You must use the Visual Studio Power Tool in the sandbox.
**External content types are typically created by using the External Content Type Designer in SharePoint Designer 2010. However, they must be deployed using a farm solution or through the Central Administration Web site.

*Note: The standard Visual Web Part is not supported in the sandbox environment. The reason for this is because Visual Web Parts effectively host an ASCX user control within the Web Part control. The ASCX file is deployed to the _controltemplates virtual directory in the physical file system on each Web front-end server. The sandbox environment does not allow you to deploy physical files to the SharePoint root, so you cannot use a sandbox solution to deploy a Visual Web Part based on the Visual Studio 2010 Visual Web Part project template. 
HOWEVER:
A Visual Studio Power Tool is available that addresses this issue. A Power Tool is a plug in for Visual Studio. The tool will generate and compile code representing the user control (.ascx) as part of the assembly. This avoids the file deployment issue. You can download a Power Tool for Visual Studio 2010 that supports Visual Web Parts in the sandbox from Visual Studio 2010 SharePoint Power Tools on MSDN.
Hybrid: Hybrid approach means, combination of sandbox solution and full-trust solution (full trust: deployed at Farm level). The sandboxed component is deployed in a SharePoint solution package (WSP) to a site collection solutions gallery, and the full trust component is deployed in a WSP to the server farm. These components are typically developed in isolation, often at different times, and a single full-trust component can be consumed by multiple sandboxed applications.
Sandbox Limitations
As Sandbox is a secured wrapper and it has restrictions on code to run in SharePoint environment. Few Key limitations which developers should know are listed below.

  1. No Security Elevation - RunWithElevatedPrivileges which runs the specified block of code in application pool account(typically System Account) context is not allowed in Sandbox code. SPSecurity class also not allowed to use in Sandbox.
  2. No Email Support - SPUtility.SendMail method has been blocked explicitly in Sandbox, However .Net mail classes can be used to send mails. Additionaly sandbox won't allow to read Farm SMTP address. So developers has to specify the SMTP address in code itself(may be some other workaround).
  3. No Support to WebPartPages Namespace - Sandbox won't allow to use Microsoft.SharePoint.WebPartPages namespace.
  4. No Support to external Webservice - Internet web service calls are not allowed to ensure security in Sandbox solutions. Allow Partially Trusted code also can't be accessed within Sandbox.
  5. No GAC Deployment - Sandbox solutions are not stored in File System(Physical path) and assemblies can't be deployed to Global Assembly Cache(GAC). But it's available on C:\ProgramData\Microsoft\SharePoint\UCCache at runtime. Note the ProgramData is a hidden folder.
  6. No Visual Webparts - Visual Studio 2010 by default won't allow to create Visual Webparts to deploy as sandbox solution. But with Visual Studio PowerTools extensions(downloadable from Microsoft MSDN website) Visual Webparts can be developed and deployed as sandbox Solutions.
Microsoft (SharePoint) Office 365 supports only Sandbox solutions, it does not allow GAC deployments or file system access. 

Sandbox solution Model and other related articles:
http://msdn.microsoft.com/en-us/library/ff798382.aspx

Also see: SharePoint 2013 Preview: Sandbox Solution à Apps

--------------------------------------------------------------------------------------------------

About me: 
Vishnu Vadla, Dallas, TX.
SharePoint Consultant.

Specialized on Microsoft Technologies 
(SharePoint, ASP.NET, SQL Server Technologies)
--------------------------------------------------------------------------------------------------

No comments:

Post a Comment