TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Ask HN: How Do Services Like PythonTutor and Repl.it Run Code Safely

31 点作者 g_delgado14超过 6 年前
I'm super curious to know how these services work under the hood. Are there any good writeups about safe execution of unknown code? Are they spinning up isolated VM's per user / connection?

6 条评论

amasad超过 6 年前
Repl.it CEO here. As @tony-allan mentioned we&#x27;re indeed container based. Containers, however, on their own aren&#x27;t safe for isolation. They&#x27;re NOT sandboxes. You need to do a lot of things around containers to secure them. Most commonly is housing them in a VM.<p>At Repl.it we have multiple layers of security with the most important being that the entire execution environment has access to zero user data. Even if someone escaped the container jail, and the VM jail, and compromised the server they really couldn&#x27;t do much beyond that.<p>We also use and built a bunch of intrusion detection software and manually look through potential threats.<p>Finally, if you want a container-based sandbox take a look at GVisor by Google. It&#x27;s still an early project but has a lot of potential.
caspervonb超过 6 年前
Working on a service in Go that does this, focusing on no fuzz embeds, yet to be launched tho and the source is not released yet either but it will be.<p>Anyway, it&#x27;s currently docker based, basically the only interesting thing is the run endpoint which is a POST request that copies the payload files to a tmpdir on disk (cached files are just represented as a path).<p>With the files available I spin up the language appropriate container with the tmpdir mounted as the working directory and the default run command (which can be overriden to specify other build options etc but there&#x27;s a reasonable default built into every docker image).<p>The output is streamed as plain-text so it works reasonably well even with no JavaScript but SSE is used when JavaScript is enabled, look a bit prettier. WebSockets are just not implemented <i>yet</i>.<p>Finally, I found it annoying not being able to preview servers etc on other playgrounds so TCP connections are proxied, each time a subdomain is accessed it looks up the port and maps it accordingly to the container.<p>There&#x27;s a bit of overhead to all this tho, from hitting the run button until seeing output can take anywhere from 10 to 60 seconds.<p>As for safe execution, people have broken out of docker containers before and no doubt people will do it in the future. Best you can do is minimize the damage breaking out of the container would be able to do by isolating the machines that run the containers from the rest of the stack.
karim超过 6 年前
I’ve actually written a short blog post about it (<a href="http:&#x2F;&#x2F;khamidou.com&#x2F;sandboxing&#x2F;" rel="nofollow">http:&#x2F;&#x2F;khamidou.com&#x2F;sandboxing&#x2F;</a>)!<p>Basically, most of them build a sandbox to prevent the guest system from interacting in unexpected ways. There’s a bunch of ways you could do this — intercepting syscall, limiting them using seccmp(2), etc.
porphyrogene超过 6 年前
This may be a good place to start.<p><a href="https:&#x2F;&#x2F;nodejs.org&#x2F;api&#x2F;repl.html" rel="nofollow">https:&#x2F;&#x2F;nodejs.org&#x2F;api&#x2F;repl.html</a><p>Generally you have a client run their own Javascript that speaks to your backend but does not run on your hardware nor within your virtual ecosystem.
评论 #19214899 未加载
tony-allan超过 6 年前
I understand that repl.it is container based.<p>See <a href="https:&#x2F;&#x2F;techcrunch.com&#x2F;2018&#x2F;03&#x2F;15&#x2F;repl-it-lets-you-program-in-your-browser&#x2F;" rel="nofollow">https:&#x2F;&#x2F;techcrunch.com&#x2F;2018&#x2F;03&#x2F;15&#x2F;repl-it-lets-you-program-i...</a>
girishso超过 6 年前
You can checkout Elm repl I wrote at <a href="https:&#x2F;&#x2F;github.com&#x2F;girishso&#x2F;elm-repl-in-browser" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;girishso&#x2F;elm-repl-in-browser</a> it uses docker container to isolate user session.