JavaScript

JavaScript Sandbox

Runs a snippet in a disposable worker and shows everything it logged and returned.

Loading the tool…

Processing happens locally in your browser. What you paste or load is processed by this page and is not uploaded to a server. Nothing is stored unless you use a control that says it stores something, and you can clear anything this site has kept from the privacy page.

How to use this tool

  1. Paste the snippet, or load a .js file with the picker.
  2. Use console.log for anything you want to see, and return a value at the end if you want it printed.
  3. Raise the timeout if the snippet does real work; leave it low while you are still experimenting.
  4. Select Run in the sandbox. The worker is discarded afterwards, so nothing carries over to the next run.

What javascript sandbox does

Most online JavaScript runners send your code to a server. This one does not, and cannot — there is no server. The snippet is compiled inside a Web Worker created from a Blob in your own browser. A worker has no document, no window, no cookies and no view of this page, so nothing you paste can read or change anything on the site. On top of that, the worker bootstrap removes fetch, XMLHttpRequest, WebSocket, EventSource and importScripts before your first line is compiled, so a snippet cannot send what it sees anywhere either.

Every run gets a fresh worker and the worker is terminated afterwards, so nothing carries over between runs. console.log, console.warn and console.error are captured and formatted the way a developer console would show them — objects expanded, functions named, circular references marked rather than crashing the output — and the value your snippet returns is printed at the end. If the snippet never finishes, it is stopped at the timeout you set: a worker cannot be interrupted from outside, so terminating it is the only honest way to end a loop that never ends.

Frequently asked questions

In your own browser, in a Web Worker created from a Blob URL. There is no server involved — this whole site is static files. A worker has no document, no window, no cookies and no access to this page, so nothing you paste can read or change anything here. The worker bootstrap also removes fetch, XMLHttpRequest, WebSocket, EventSource and importScripts before your first line is compiled, so a snippet has no way to send anything anywhere.

No. Every run creates a new worker and terminates it when the run ends or the timeout fires. A variable you defined last time is gone, and so is anything the previous snippet did. If you want state to carry across lines, put it all in one snippet.

It runs until the timeout, then the worker is terminated and you are told the run was stopped. Anything logged before that point is still shown. A worker running a tight loop never yields, so it cannot be politely interrupted from outside — terminating it is the only thing that actually works, which is why the timeout exists rather than a cancel button.

Yes. If your snippet returns a promise the result waits for it to settle and prints the resolved value, or the rejection if it rejects. Bear in mind that anything network-shaped will not work, because those globals have been removed — setTimeout and the promise machinery itself are all still there.