I’ve seen parrotfish do this many times, and what comes out, of course, is sand. If you want to see what comes out when sharks do it, just check out this video here.
When snorkeling or free-diving around anchored boats I always keep a close eye on any through-hulls I spy for exactly this reason.
In this case, I wonder if the shark is expressing an editorial opinion with respect to the humans in the cages. I also find the immediate response of all the little fish in the vicinity to be very interesting. Looks to me like they are–pardon my saying it–eating shit.
As my daughter would say: ewww, gross.