The following works:
def spam():
print \"spam\"
exec(spam.__code__)
spam
But what if spam
Can you change the function to not take any arguments? The variables is then looked up from the locals/globals where you can supply into exec:
>>> def spam():
... print "spam and", eggs
...
>>> exec(spam.__code__, {'eggs':'pasta'})
spam and pasta
(Why not just send the whole function as a string? Pickle "def spam(eggs): print 'spam and', eggs", and exec the string (after verification) on the other side.)