(as pointed out, this answer is outdated and the proposed solution could be easily broken).
Currently, draft for secure ecmascript has not been approved/implemented yet.
One hack that has decent browser support (proxy is es6 feature) is using proxies
and with
to create a sandbox.
You just have to write a proxy which returns null for every requested key except for some safe functions.
with
would ask the proxy every time a var outside eval is required (for example, window) and so, provide null instead of the real var.
Check this website for a tutorial:
code sandbox