MCPcopy
hub / github.com/evalplus/evalplus / reliability_guard

Function reliability_guard

evalplus/eval/utils.py:102–187  ·  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- ge

(maximum_memory_bytes: Optional[int] = None)

Source from the content-addressed store, hash-verified

100
101
102def reliability_guard(maximum_memory_bytes: Optional[int] = None):
103 """
104 This disables various destructive functions and prevents the generated code
105 from interfering with the test (e.g. fork bomb, killing other processes,
106 removing filesystem files, etc.)
107
108 WARNING
109 This function is NOT a security sandbox. Untrusted code, including, model-
110 generated code, should not be blindly executed outside of one. See the
111 Codex paper for more information about OpenAI's code sandbox, and proceed
112 with caution.
113 """
114
115 if maximum_memory_bytes is not None:
116 import resource
117
118 resource.setrlimit(
119 resource.RLIMIT_AS, (maximum_memory_bytes, maximum_memory_bytes)
120 )
121 resource.setrlimit(
122 resource.RLIMIT_DATA, (maximum_memory_bytes, maximum_memory_bytes)
123 )
124 if not platform.uname().system == "Darwin":
125 resource.setrlimit(
126 resource.RLIMIT_STACK, (maximum_memory_bytes, maximum_memory_bytes)
127 )
128
129 faulthandler.disable()
130
131 import builtins
132
133 builtins.exit = None
134 builtins.quit = None
135
136 import os
137
138 os.environ["OMP_NUM_THREADS"] = "1"
139
140 os.kill = None
141 os.system = None
142 os.putenv = None
143 os.remove = None
144 os.removedirs = None
145 os.rmdir = None
146 os.fchdir = None
147 os.setuid = None
148 os.fork = None
149 os.forkpty = None
150 os.killpg = None
151 os.rename = None
152 os.renames = None
153 os.truncate = None
154 os.replace = None
155 os.unlink = None
156 os.fchmod = None
157 os.fchown = None
158 os.chmod = None
159 os.chown = None

Callers 5

safety_testFunction · 0.90
unsafe_executeFunction · 0.90
unsafe_executeFunction · 0.90
sample_one_inputFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected