Code injection on Linux and macOS can be achieved using LD_PRELOAD and DYLD_INSERT_LIBRARIES. These mechanisms allow you to override system calls and shared libraries, changing the behavior of a program without modifying its source code. This technique has various uses such as manipulating time, making a process appear as root, or simulating changes in the filesystem's root directory. However, there are limitations and security concerns associated with this approach.