Commas are definitely nonstandard in edited prose in cases like this. You can't write
"I wonder what Joe is doing," he scratched his head.
so you're equally unable to write
"I wonder what," he scratched his head, "Joe is doing."
Correct versions:
"I wonder what Joe is doing." He scratched his head.
"I wonder what"--he scratched his head--"Joe is doing."
Of course, Patrick O'Brien often writes stuff like
"I wonder what," scratching his head, "Joe is doing."
which would also be considered nonstandard--though I don't know how he punctuates it, since I've only listened to his books on tape. If it were like this
"I wonder what," he said, scratching his head, "Joe is doing."
that would be standard, but O'Brien leaves off the "he said" part a lot. But if you do say "he said, scratching his head," the ordering of events becomes unclear; is the headscratching going on between the two utterances, or is it happening during the entire utterance, or only during the first part, or at some definite time approximately in the middle of the utterance but being overlapped by same?