Fixing sandboxd: mdworker deny mach-lookup error in OSX 10.8.2 (and other versions)

I recently experienced this problem and besides filling your console logs with garbage, it seems to slow down Time Machine to the point where it is useless. It seems to be related to Spotlight and is in some way related to an update that Apple pushed out.

Here's how I fixed it:

  1. Restart your computer in safe mode (read that link for more info about what it will do.) This is done by restarting as normal from the Apple menu, then holding down shift after you hear the Apple noise on startup. Note, you must wait to hold down shift until after the Apple noise has started. As proof that you're loading into safe mode, you'll see a little progress bar beneath the Apple and you'll have to wait a while.
  2. Once the wait is over, you can log into OSX, but since you're still in safe mode you'll want to restart again, this time without holding shift.
  3. Log in again, check your Console -- if this worked, the error should be gone.

If this solves your problem, please comment below and let me know it worked. Thanks!

J. Wolfie writes:
Just thought you might like some more detailed information - as well as a fix for those who can't boot into safe mode for some reason. (My machine will hang at about 30% for hours - even tried over night and after doing a cmd-R disk check… strange stuff indeed…)
Quoted from a Macrumors post by Phobox:

You can completely fix all the mdworker related sandbox errors in Console (including the 'cannot talk to lsboxd') by editing the profile rather than the mdworker ones. The file is used by all Apple system processes that run under the sandbox, including mdworker. If you modify this file (which is located in /System/Library/Sandbox/Profiles) to include:

(allow mach-lookup (global-name ""))

(allow mach-lookup (local-name ""))

This will stop all the lsbox related mdworker issues.

I must warn however that modifying this file is potentially dangerous if you're not really sure what you're doing. Take a backup of it just in case. And only add the lines above, do not modify anything else.

This explanation seems to make it clear that what is happening is the new sandboxing features of Mountain Lion no longer see Spotlight as a trusted entity -- restarting in Safe mode probably rebuilds a bunch of files and clears caches from previous versions (like 10.8.1 perhaps) so that it does. If restarting in safe mode does not work for you (and most of the time it should) the above secondary method could work for you since it's more or less doing something similar.
Recent feedback on this solution (12/19/2012):
Jim B. from Canada:
This problem really did not show itself until I have to do a full reinstall. Yea, good backup habits do pay off! I was actually dealing with a problem of my mac (iMac i7 20G Ram) where the mac would freeze for a few seconds and then would start working fine. I finally got pissed off enough to look into the problem. I was everything from reinstall to modify permissions on system files, to deleting preference files. I also found your solution. The reinstall was a stupid solution as I just did that and I do not like deleting files in the /library directory because some expert on the web said so. yours seemed to be the easiest and less destructive to say the least. It looks like it cleared up the problem and so, now it is time to move onto the next problem(s). I really hate looking in the system log, because it almost almost involves more work!
And Jim B. from the US
Your solution of restarting in safe mode worked for me. Thanks.
So basically, if your name is Jim, it will probably work.