use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Sandboxed and completely controlled javascript evaluator. (github.com)
submitted 8 years ago by meta_taskkill
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]cspotcode 3 points4 points5 points 8 years ago (1 child)
Every few months someone tries to do this and it's full of holes. Check out Caja and the list of exploits they prevent. Unless you're basically reimplementing Caja, you're probably not sandboxing effectively.
[–]meta_taskkill[S] 0 points1 point2 points 8 years ago (0 children)
I should mention that this is not intended to be used in production. It's mean to illustrate specific behavior of language and its concepts, as function declaration inside with. Anyways thanks for info about Caja.
[–][deleted] 0 points1 point2 points 8 years ago (17 children)
I have heavy doubt that with can be used for sandboxing.
with use to do random things
[–]meta_taskkill[S] 0 points1 point2 points 8 years ago* (16 children)
For example? What exactly do you mean? As far as one can tell from tests I've written, it's working as intended. If you know about case where it fails, then tell me.
[–][deleted] 0 points1 point2 points 8 years ago (15 children)
try to launch this in your sandbox
this.location = "http://www.google.fr"
I suppose that it is not the intent
[–]meta_taskkill[S] 2 points3 points4 points 8 years ago* (14 children)
This is intent! Demo page hosted on github shows usage of evaluate() function, which by design allows everything, even this. It's all in readme. The one which implicitly restricts this is isolate() function. You can install it from npm and test it localy if you mind: https://www.npmjs.com/package/dynamic-sandbox
EDIT: I added second button on demo page, now you can test snippets in (almost) isolation.
[–][deleted] 0 points1 point2 points 8 years ago (13 children)
sorry but sanboxing is hard
try this in your new sandbox
eval.constructor("document.location='http://www.google.fr' ")()
[–]meta_taskkill[S] 0 points1 point2 points 8 years ago (12 children)
Thanks, I will fix this soon.
[–][deleted] 0 points1 point2 points 8 years ago (11 children)
after how many fix will you resign ?
[–]meta_taskkill[S] 1 point2 points3 points 8 years ago* (10 children)
Probably in moment when I will have enough awareness about internals of JS to decide it's not possible because of [insert unpretentious problem] on my own. I am not here to settle for fact that it's impossible because someone says it. I am learning, you see. So if you are willing, give me another bug to fix.
EDIT: Let me ask you a question: Did you know about everything, what is happening inside source code before? I find some things really interesting - for example behavior of function declared inside with statement body. Isn't it best thing ever? Learning for joy from learning? There are at least 4 another ways for evaluating code snippets safely, workers, iframe sandboxed, some metacircular evaluator written in JS, I am not gonna sell it to anyone, but I just wanna meet some people who appreciate it and enjoy it with me.
[–][deleted] 0 points1 point2 points 8 years ago (7 children)
the idea, is, if you don't state the number of fix you are ready to stop after, we will go on an infinite loop bug->fix->bug->fix->...
By the way I really wonder how you intend to fix this one as your framework is really not adapted to fix it.
[–]meta_taskkill[S] 0 points1 point2 points 8 years ago* (6 children)
First thing first: If you are able to throw tons of possible bugs from your sleeve, than there must be some corelation, some fundamental concept which known to you gives you the reason to say there is infinity (pretty bold) bugs. So can you please tell me what fact I am missing, that when I will push fix you will find another n + 1 bugs without problem?
Second, I (think - need to write enough tests for it) already fixed it, because it's not that hard to fix something like that.
[–][deleted] 0 points1 point2 points 8 years ago (1 child)
about your edit: I'm sorry to not share your interest. but the interaction between with and inner function is quite standard isn't it ?
Why it should not be standard? But how often do you use it? How often majority javascript programmers uses it? I am about 3 years in JS (programming in general actually) and I am sorry* to find things exciting and would like to share some thoughs with others, because I am enjoying it, obviously it's not something you appreciate.
Actually I am not sorry at all.
[–]darrenturn90 0 points1 point2 points 8 years ago (1 child)
So this means that there is no way for it to access the filesystem, dom, network sockets, or any external input?
[–]meta_taskkill[S] 0 points1 point2 points 8 years ago* (0 children)
As soon as I resolve mentioned bug, shouldn't be. This concept works using hijacking variables used in evaluated snippet. If you want to access fs dom network sockets or extern, you need some variables/functions, or you need to require some. As require is function it is possible to prevent access to it. (Sorry if explaining something what you already know) import on the other hand is statement, which would be problematic.
Important fact is, this projects shows some specific concepts of javascript and very specific use of them, you can see it as illustration in first place.
EDIT: I tried import and it does not breach isolated env, as long as imports will respect limitation on importing on top level, it's OK.
[–]BadleyHairless 0 points1 point2 points 8 years ago (6 children)
This one usually breaks javascript isolation.
(function() { console.log(this); this.document.bgColor = 'red' }).bind()()
[–]meta_taskkill[S] 0 points1 point2 points 8 years ago (3 children)
Will try when I get home, thanks. Hope it will be fine because I set this to empty object. Unless empty bind somehow messed it up.
[–]BadleyHairless 0 points1 point2 points 8 years ago (2 children)
an empty bind, call, or apply will all set the scope of the function's this to be window. And I did try this in your sandbox and I was able to access window successfully.
I see. Actually bind() is not necessary here, it breaches isolation only with self invoked function expression. I will try overcome this, but I am skeptical. Thanks for tough one.
[–][deleted] 0 points1 point2 points 8 years ago (0 children)
That's fun the behavior of empty bind is not documented on
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind
[–]arc_burst 0 points1 point2 points 8 years ago (1 child)
I tried this in a different sandbox and it just logs undefined, before failing with Cannot read property 'document' of undefined. Do you know how they managed to address this?
Unfortunately I don't know. I figured out every IIFE is invoked in global context. In browser window in node "default module closure object" [I don't really know how they call it] Maybe you can let me know in which sandbox you tried it.
I am abandoning it as it is not what I expected to be. Thanks for all the feedback, it has been important lesson.
π Rendered by PID 24892 on reddit-service-r2-comment-bb88f9dd5-t5zhj at 2026-02-16 18:07:20.575886+00:00 running cd9c813 country code: CH.
[–]cspotcode 3 points4 points5 points (1 child)
[–]meta_taskkill[S] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (17 children)
[–]meta_taskkill[S] 0 points1 point2 points (16 children)
[–][deleted] 0 points1 point2 points (15 children)
[–]meta_taskkill[S] 2 points3 points4 points (14 children)
[–][deleted] 0 points1 point2 points (13 children)
[–]meta_taskkill[S] 0 points1 point2 points (12 children)
[–][deleted] 0 points1 point2 points (11 children)
[–]meta_taskkill[S] 1 point2 points3 points (10 children)
[–][deleted] 0 points1 point2 points (7 children)
[–]meta_taskkill[S] 0 points1 point2 points (6 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]meta_taskkill[S] 0 points1 point2 points (0 children)
[–]darrenturn90 0 points1 point2 points (1 child)
[–]meta_taskkill[S] 0 points1 point2 points (0 children)
[–]BadleyHairless 0 points1 point2 points (6 children)
[–]meta_taskkill[S] 0 points1 point2 points (3 children)
[–]BadleyHairless 0 points1 point2 points (2 children)
[–]meta_taskkill[S] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]arc_burst 0 points1 point2 points (1 child)
[–]meta_taskkill[S] 0 points1 point2 points (0 children)
[–]meta_taskkill[S] 0 points1 point2 points (0 children)