MCPcopy Create free account
hub / github.com/InternScience/SciReason / reliability_guard

Function reliability_guard

opencompass/datasets/apps.py:800–877  ·  view source on GitHub ↗

This disables various destructive functions and prevents the generated code from interfering with the test (e.g. fork bomb, killing other processes, removing filesystem files, etc.) WARNING This function is NOT a security sandbox. Untrusted code, including, model- generated code, sh

(maximum_memory_bytes=None)

Source from the content-addressed store, hash-verified

798
799
800def reliability_guard(maximum_memory_bytes=None):
801 """This disables various destructive functions and prevents the generated
802 code from interfering with the test (e.g. fork bomb, killing other
803 processes, removing filesystem files, etc.) WARNING This function is NOT a
804 security sandbox.
805
806 Untrusted code, including, model- generated code, should not be blindly
807 executed outside of one. See the Codex paper for more information about
808 OpenAI's code sandbox, and proceed with caution.
809 """
810
811 if maximum_memory_bytes is not None:
812 import resource
813
814 resource.setrlimit(resource.RLIMIT_AS,
815 (maximum_memory_bytes, maximum_memory_bytes))
816 resource.setrlimit(resource.RLIMIT_DATA,
817 (maximum_memory_bytes, maximum_memory_bytes))
818 if not platform.uname().system == 'Darwin':
819 resource.setrlimit(resource.RLIMIT_STACK,
820 (maximum_memory_bytes, maximum_memory_bytes))
821
822 faulthandler.disable()
823
824 import builtins
825
826 builtins.exit = None
827 builtins.quit = None
828
829 os.environ['OMP_NUM_THREADS'] = '1'
830
831 os.kill = None
832 os.system = None
833 os.putenv = None
834 os.remove = None
835 os.removedirs = None
836 os.rmdir = None
837 os.fchdir = None
838 os.setuid = None
839 os.fork = None
840 os.forkpty = None
841 os.killpg = None
842 os.rename = None
843 os.renames = None
844 os.truncate = None
845 os.replace = None
846 os.unlink = None
847 os.fchmod = None
848 os.fchown = None
849 os.chmod = None
850 os.chown = None
851 os.chroot = None
852 os.fchdir = None
853 os.lchflags = None
854 os.lchmod = None
855 os.lchown = None
856 os.getcwd = None
857 os.chdir = None

Callers 1

run_testFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected