Your callback would have your capabilities in scope, so your user code would still be able to do whatever you want, even when called by an untrusted library.
I.e. something like:
import capabilities;
import fs;
import someLibrary;
const root = capabilities.claimRootToken();
someLibrary.onEvent(() => {
fs.writeSync(root, ...);
});