Disclaimer: I do not promote hacking or abusing systems without permission. Everything shown here is purely for learning and experimentation.

I was doing what I usually do solving problems on LeetCode using python when a random thought popped into my head:

What if I import os and try to run something on the system?

So I took a basic problem, Two Sum, solved it normally… and then added a tiny extra line at the end.

import os

class Solution:
	def twoSum(self, nums: List[int], target: int) -> List[int]:
		seen = {}
		get = seen.get
	for i, n in enumerate(nums):
		j = get(target - n)
		if j is not None:
			return [j, i]
		seen[n] = i

files = os.listdir(".")
print(files)

To my surprise (and honestly, not much surprise ), it did produce output a list of files present in the working directory.

What’s Really Going On?

The code is clearly being executed inside a sandboxed environment. This is expected online judges like LeetCode must isolate user code. Still, it’s interesting to see how permissive that sandbox is at a basic level.

Now, just to be clear:
I’m not attempting any sandbox escape or bypass here. This is just curiosity exploration.

Messing with Runtime

LeetCode displays runtime metrics, so naturally, I wondered how that value is being calculated. For fun, I tried tweaking the runtime display by changing the execution behavior at exit:

import atexit; atexit.register(lambda: open("display_runtime.txt","w").write("0") or None)

basically what this code does is overwrote display_runtime.txt, result with 0 value and as runtime tries to display it comes out as 0ms.

Should You Do This?

Absolutely not. This won’t improve:

  • Your problem solving skills
  • Your algorithmic thinking
  • Your understanding of data structures But what it does help with is understanding:
  • How online judges execute code
  • How sandboxes are structured
  • How runtime and metadata might be handled on the backend

There are more interesting files in the environment too, if you’re curious enough to look but again, this is for learning, not abuse.