Add Darwin sandbox support

This patch adds Darwin sandbox support. It is a port and cleanup of the MacPorts patch.