However, if you're using CodeSandbox, your code is execute in the same tab as the editor. This can make it impossible to fix the bug that's locking the main thread. Thankfully, CodeSandbox has an undocumented way of getting around this.
If you append
&runonclick=1 to the end of a project's URL, it will prevent the code preview from running until you click into the preview window. This will allow you to fix your buggy code before it locks up the main thread.
At the time of writing this post, there is no way to do this through the UI.