Skip to main content

Command Palette

Search for a command to run...

Create a code sandbox with docker-run

Published
2 min read

How to create a simple web page that let's you run python code (or any other language) from the browser: image.png

These instructions are for ubuntu 20.10, but should be similar for other linux distros.

Install docker-run

Docker-run will be used to run the code. Follow the instructions to install docker-run. Make sure you pull the python image:

docker pull glot/python:latest

Install nginx

Nginx will be used to host the web page

apt install nginx

Add a new site to nginx

curl https://gist.githubusercontent.com/prasmussen/5b1e2a42b295316dd8b1f665fa8589a7/raw/23811a690a7ce446e43c55f37d331403ec91994a/code-sandbox.conf > /etc/nginx/sites-enabled/code-sandbox

Restart nginx to enable the new site

systemctl restart nginx.service

Add the web page

mkdir /home/glot/www
curl https://gist.githubusercontent.com/prasmussen/5b1e2a42b295316dd8b1f665fa8589a7/raw/23811a690a7ce446e43c55f37d331403ec91994a/index.html > /home/glot/www/index.html

Edit /home/glot/www/index.html and change token in the X-Access-Token header to the token you configured when installing docker-run.

Your code sandbox should now be available at http://<your ip>:8000.

Please read the security section before making your web page available on the internet. Good luck!