A small utility to wrap a function in a context.
This is used to provide secure contexts for running functions.