MCPcopy Create free account
hub / github.com/huggingface/evaluate / reliability_guard

Function reliability_guard

metrics/code_eval/execute.py:158–236  ·  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

(maximum_memory_bytes=None)

Source from the content-addressed store, hash-verified

156
157
158def reliability_guard(maximum_memory_bytes=None):
159 """
160 This disables various destructive functions and prevents the generated code
161 from interfering with the test (e.g. fork bomb, killing other processes,
162 removing filesystem files, etc.)
163
164 WARNING
165 This function is NOT a security sandbox. Untrusted code, including, model-
166 generated code, should not be blindly executed outside of one. See the
167 Codex paper for more information about OpenAI's code sandbox, and proceed
168 with caution.
169 """
170
171 if maximum_memory_bytes is not None:
172 import resource
173
174 resource.setrlimit(resource.RLIMIT_AS, (maximum_memory_bytes, maximum_memory_bytes))
175 resource.setrlimit(resource.RLIMIT_DATA, (maximum_memory_bytes, maximum_memory_bytes))
176 if not platform.uname().system == "Darwin":
177 resource.setrlimit(resource.RLIMIT_STACK, (maximum_memory_bytes, maximum_memory_bytes))
178
179 faulthandler.disable()
180
181 import builtins
182
183 builtins.exit = None
184 builtins.quit = None
185
186 import os
187
188 os.environ["OMP_NUM_THREADS"] = "1"
189
190 os.kill = None
191 os.system = None
192 os.putenv = None
193 os.remove = None
194 os.removedirs = None
195 os.rmdir = None
196 os.fchdir = None
197 os.setuid = None
198 os.fork = None
199 os.forkpty = None
200 os.killpg = None
201 os.rename = None
202 os.renames = None
203 os.truncate = None
204 os.replace = None
205 os.unlink = None
206 os.fchmod = None
207 os.fchown = None
208 os.chmod = None
209 os.chown = None
210 os.chroot = None
211 os.fchdir = None
212 os.lchflags = None
213 os.lchmod = None
214 os.lchown = None
215 os.getcwd = None

Callers 1

unsafe_executeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…