One wonders at which point models will be sneaky enough to bypass simple eval sandboxes. The article has: # Evaluate the equation with restricted globals and locals result = eval(equation, {"__builtins__": None}, {}) but that's not enough as you can rebuild access to builtins from objects and then go from there: https://ideone.com/qzNtyu By the way, writing this greatly benefited from DeepThink-r1 while o1 just gave…
In this specific case, it's safe, as that wouldn't pass the regex just a few line before the eval :
# Define a regex pattern that only allows numbers,
# operators, parentheses, and whitespace
allowed_pattern = r'^[\d+\-*/().\s]+$'
Commenting on the R1 reproduction, the heavy lifting there is done by huggingface's trl[0] library, and the heavy use of compute.[0] Transformer Reinforcement Learning - https://huggingface.co/docs/trl/en/index