Unless approached very carefully this has some frightening XSS implications: innocent looking HTML entered into comments could suddenly become automatically executed JavaScript.
A smart thing to do would be to run it in an iframe with the sandbox attribute so that it doesn't get access to the page's or origin's data, but that wouldn't protect from local denial-of-service attacks against the browser that infinitely loop or allocate tons of memory.