TLDR · PROGRAMMING, DESIGN & DATA SCIENCE
WICKED PYTHON TRICKERY - DYNAMICALLY PATCH A PYTHON FUNCTION'S SOURCE CODE AT RUNTIME
Summary from the TLDR newsletter
It's possible to dynamically change a function's source code at run time in Python using the compile and exec functions. This technique enables developers to build more flexible AI bots that can generate and execute code with access to the current environment. However, it also raises some serious security concerns. This post walks readers through how the technique works and the real security concerns with using the approach.