Tuesday, January 7, 2014

Sandboxed code sometimes failing with "Sandboxed code execution request failed"

Nice and short one here (which unfortunately took me a long time to pin down).  I have a simple webpart running in a sandboxed solution.  The webpart has a label and a button, and there is no other code-behind.

Sometimes, when rendering the web part, I get the error:

[SPUserCodeExecutionPipelineFailedException: Sandboxed code execution request failed.]

It's not a nice error but it only appears sometimes.  I'm running on a four-server farm so I assumed it was something to do with the sandboxed code service not running on one of the servers.  However, the service was running on all of them.

It's probably not solved anything (but it's a development environment so I'm not too bothered), but I found a workaround:

  1. Go to Central Administration
  2. Click on System Settings, and then Manage user solutions
  3. In this screen, select "All sandboxed code runs on the same machine as a request".
  4. Click OK.

The webpart now works reliably.  I'm assuming one of my servers isn't happy with the sandbox service credentials but I can move on with my life for now.