From the list of command line options for python there doesn't seem to be this option (and sandboxing to prevent IO appears to not be too effective). You could make your own command arguments to gain this functionality, for example
import argparse
class blockIOError(Exception):
pass
parser = argparse.ArgumentParser(description='Block IO operations')
parser.add_argument('-bIO','-blockIO',
action='store_true',
help='Flag to prevent input/output (default: False)')
args = parser.parse_args()
blockIO = args.bIO
if not blockIO:
with open('filename.txt') as f:
print(f.read())
else:
raise blockIOError("Error -- input/output not allowed")
The down side is you need to wrap every open, read etc in an if statement. The advantage is you can specify exactly what you want to allow. Output then would look like:
$ python 36477901.py -bIO
Traceback (most recent call last):
File "36477901.py", line 19, in <module>
raise blockIOError("Error -- input/output not allowed")
__main__.blockIOError: Error -- input/output not allowed