Discuss Scratch
- ninjaMAR
-
Scratcher
1000+ posts
Run python scripts from the browser
I made a way to run python scripts in the browser.
Make a POST request https://webpython.ninjamar.repl.co/api/runpy and send JSON data to it.
JSON data:
Response
Make sure the repl it running.
ToDo:
send back data better
Make a POST request https://webpython.ninjamar.repl.co/api/runpy and send JSON data to it.
JSON data:
{ "script":"YOURCODEHERE" }
{ "script":XYZ "output":XYZ "timestamp":XYZ }
ToDo:
send back data better
Last edited by ninjaMAR (Feb. 24, 2021 13:53:35)
- imfh
-
Scratcher
1000+ posts
Run python scripts from the browser
Hmm…
Please don't run this on an important server.
{"script": "import os; os.system('ls')"}
Please don't run this on an important server.

- Chiroyce
-
Scratcher
1000+ posts
Run python scripts from the browser
I made a way to run python scripts in the browser.
Make a POST request https://webpython.ninjamar.repl.co/api/runpy and send JSON data to it.
ERROR: Hmmmm.... We Couldn't Reach Your Repl
Make sure your repl has a port open and is ready to receive HTTP traffic.
- 9gr
-
Scratcher
1000+ posts
Run python scripts from the browser
Do you have repl.it pro? Because you need it to keep the repl on always
- ninjaMAR
-
Scratcher
1000+ posts
Run python scripts from the browser
I need to run the repl always. I thought the page would get HTTP traffic and start up. For now just go to the page and it should run. I just used a pinger and it worksI made a way to run python scripts in the browser.
Make a POST request https://webpython.ninjamar.repl.co/api/runpy and send JSON data to it.ERROR: Hmmmm.... We Couldn't Reach Your Repl
Make sure your repl has a port open and is ready to receive HTTP traffic.
Do you have repl.it pro? Because you need it to keep the repl on alwaysI do not have repl..it pro
Last edited by ninjaMAR (Feb. 21, 2021 15:20:20)
- Danger_script
-
Scratcher
20 posts
Run python scripts from the browser
You could always also use Jupiter notebook in the browser as well. Jupiter is great for people that are into machine learning in python.
- ninjaMAR
-
Scratcher
1000+ posts
Run python scripts from the browser
You could always also use Jupiter notebook in the browser as well. Jupiter is great for people that are into machine learning in python.How would it help me?
- imfh
-
Scratcher
1000+ posts
Run python scripts from the browser
Ehh, maybe? https://wiki.python.org/moin/SandboxedPythonHmm…I run it using this so if you deleted all files I would just restore it.{"script": "import os; os.system('ls')"}
Please don't run this on an important server.
Could I run the files in a sandbox?
Someone could also download your scripts using something like:
import os; os.system("tar -cz . | base64")
- ninjaMAR
-
Scratcher
1000+ posts
Run python scripts from the browser
I need a way to restrict terminal commandsEhh, maybe? https://wiki.python.org/moin/SandboxedPythonHmm…I run it using this so if you deleted all files I would just restore it.{"script": "import os; os.system('ls')"}
Please don't run this on an important server.
Could I run the files in a sandbox?
Someone could also download your scripts using something like:import os; os.system("tar -cz . | base64")
- Firesoldier999
-
Scratcher
28 posts
Run python scripts from the browser
Install proot with the terminal commandI need a way to restrict terminal commandsEhh, maybe? https://wiki.python.org/moin/SandboxedPythonHmm…I run it using this so if you deleted all files I would just restore it.{"script": "import os; os.system('ls')"}
Please don't run this on an important server.
Could I run the files in a sandbox?
Someone could also download your scripts using something like:import os; os.system("tar -cz . | base64")
if ! which proot > /dev/null; then install-pkg proot; fi
Now create a directory named “sandbox”, and run `proot -r sandbox python <filename>.py` whenever you need to run a script. Make sure to copy all of Python's dependencies (such as libc) and maybe /bin/sh into the sandbox directory.
- Firesoldier999
-
Scratcher
28 posts
Run python scripts from the browser
Also, I can kill the running server and override it with my own:
import os
from flask import Flask
# kill running python instance
os.system('killall python')
# start new server
app = Flask(__name__)
@app.route('/')
def index():
return 'hacked'
app.run(host='0.0.0.0', port=8080)
- ninjaMAR
-
Scratcher
1000+ posts
Run python scripts from the browser
I can not get the sandbox to workInstall proot with the terminal commandI need a way to restrict terminal commandsEhh, maybe? https://wiki.python.org/moin/SandboxedPythonHmm…I run it using this so if you deleted all files I would just restore it.{"script": "import os; os.system('ls')"}
Please don't run this on an important server.
Could I run the files in a sandbox?
Someone could also download your scripts using something like:import os; os.system("tar -cz . | base64")(make sure to do this when the server starts up)if ! which proot > /dev/null; then install-pkg proot; fi
Now create a directory named “sandbox”, and run `proot -r sandbox python <filename>.py` whenever you need to run a script. Make sure to copy all of Python's dependencies (such as libc) and maybe /bin/sh into the sandbox directory.
- Chiroyce
-
Scratcher
1000+ posts
Run python scripts from the browser
Ok, I maybe acting like a noob but whats wrong with this?

I am running that here https://webpython.ninjamar.repl.co/api/runpy

I am running that here https://webpython.ninjamar.repl.co/api/runpy
Last edited by Chiroyce (Feb. 24, 2021 14:14:20)
- ninjaMAR
-
Scratcher
1000+ posts
Run python scripts from the browser
Ok, I maybe acting like a noob but whats wrong with this?You never send the request.
I am running that here https://webpython.ninjamar.repl.co/api/runpy
const data = { "script":"CODEHERE" } const url = 'https://webpython.ninjamar.repl.co/api/runpy' fetch(url, {method: "POST", body: JSON.parse(data)});
Last edited by ninjaMAR (Feb. 24, 2021 22:48:34)
- Chiroyce
-
Scratcher
1000+ posts
Run python scripts from the browser
Is this a problem with my browser?
Firefox:

I tried with the latest version of Chrome:


Firefox:

I tried with the latest version of Chrome:


Last edited by Chiroyce (Feb. 24, 2021 14:31:56)
- imfh
-
Scratcher
1000+ posts
Run python scripts from the browser
You need to put the script in quotes. print(“Hello”) and ‘print(“Hello”)’ are two different things. print by itself is a function that I believe returns nothing, while the one inside quotes is a string which is sent to the server.