You can run untrusted code in an iframe (possibly with the sandbox attribute set). I think this would be what you're looking for.
type in
console.log("foo")
and click either button. It has access to the console even from the sandbox. Is there a way to say: I want this iframe to run a script, but don't give the script access to the console?