title: Can I sandbox 3rd party JavaScript to protect the global namespace?
body: <p>At work I have to deal with a lot of (sometimes awful) JavaScript that vendors expect us to drop into our websites. Some of them add arbitrary, un-namespaced, names to the global scope. I've been toying with different ideas about sandboxing these programs so they don't have direct access to the global scope, but I haven't been able to think of anything that might actually work. (I thought of evalling the fetched code, but I'm convinced that's a bad idea.)</p>
  
  <p>What solutions are there to keep the global scope clean while still using arbitrary 3rd party JavaScript?</p>
  
  <p>Edit: @kirilloid's comment tells me I haven't been clear about how this code is delivered. I'm not usually given <em>code</em> to put into our website. Most of the time, I'm just given a URL and asked to create a <code>script</code> tag that points to it.</p>