Skip to content
IGCSE·Tuition
Computer Science · Lessons

Use a safe browser runtime without network or file access

A practice window that runs your code is useful, but only if you know what it will refuse to do.

On this page
  1. What does a restricted runtime allow and refuse?
  2. Worked example
  3. The mistake to watch for
  4. Check yourself
  5. Where this leads next

A safe runtime runs short pieces of Python in your browser without network access or file access, and stops any program that runs too long. It is a place to test your reasoning, not a full computer.

This lesson belongs to Python transition and execution and builds on telling syntax errors from wrong results.

What does a restricted runtime allow and refuse?

AllowedRefused or outside its purpose
Variables, arithmetic, comparisonsOpening or saving files
if, elif, elseUsing the internet
for and while loopsLoops that never end (stopped by a limit)
Lists, functions, printHeavy libraries and large data

Our Python reasoning sandbox is built with a time limit and a memory limit, so a program that never ends is stopped instead of freezing the page. Keep real personal data out of browser tools.

Worked example

Task: print a countdown from 10 in steps of 3. Here is a first attempt.

n = 10
while n > 0:
    print(n)

Step 1, trace. n starts at 10. The test 10 > 0 is True, so 10 is printed. Nothing changes n, so the test is True again, and 10 is printed again, forever.

Step 2, expect the limit. The runtime stops the program when its time limit is reached. The output is a long list of 10s followed by a stop message. The runtime stopping it is correct behaviour, and the fault is yours.

Step 3, repair. The loop must move n towards the exit.

n = 10
while n > 0:
    print(n)
    n = n - 3

Step 4, trace again.

n at the testn > 0printedn after
10True107
7True74
4True41
1True1-2
-2False

The output is 10, 7, 4, 1.

The mistake to watch for

A frequent slip is to write an exercise that depends on a file.

Mistaken answer: lines = open("scores.txt").read()

The runtime has no file access, so this fails. The mistake is in the exercise design, not in your logic.

The correction is to put the data in the program itself: scores = [72, 45, 50, 38, 91]. The algorithm is the same whether the numbers come from a file or a list, and in the exam you reason about the algorithm. Use invented values only.

Check yourself

1. Why does while True: with no way out not freeze the page in the sandbox?

Show answer

The runtime has a time limit and stops the program when it is reached, then shows a message.

2. Rewrite this so it works without a file: names = open("class.txt").read().

Show answer

names = ["Ali", "Mei", "Ravi"]. Use made-up names, and the rest of the algorithm stays unchanged.

3. What is output by this program?

n = 2
while n < 30:
    n = n * 3
print(n)
Show answer

n goes 2, then 6, then 18, then 54. At 54 the test 54 < 30 is False, so the loop stops. Output: 54.

Where this leads next

Next, see why exam-year advice must be labelled in keeping 2029 Python-only guidance separate. Practise loop tracing in the restricted pseudocode trace trainer and then run the same logic in the Python reasoning sandbox.

If you would like guided practice on loops and testing, see our online one-to-one Computer Science tuition.

Questions people ask

Why can the sandbox not read files or use the internet?

It is built to run short practice exercises without network or filesystem access, so your code cannot send or fetch anything. Exercises must carry their own data, for example in a list written inside the code.

Is the sandbox a complete Python installation?

No. It is meant for small reasoning exercises, with limits on time and memory. Features that need files, the network or large libraries are outside its purpose, so check what a practice exercise needs before you rely on it.

Should I put personal details into the sandbox?

No. Use made-up values such as names like Ali or Mei and invented marks. Treat any practice window as a place for example data only, and never paste passwords, identity numbers or real contact details.

Updated:

Your next step

If you are unsure how to turn a file or input question into something a small runtime can run, a one-to-one teacher can show you how to model it with a list.

Paid one-hour trial at your assigned teacher’s confirmed rate, starting from RM80. Other fees, schedules and ongoing arrangements are confirmed directly with your teacher after the trial class.

Tuition is arranged with a parent or guardian. Send them this page on WhatsApp and they can enquire for you.

Parent or guardian? Enquire here

9,000+ students helped through our service