For the old LSO based code, they just copy the raw data block. It's one simple and fast operation, basically downloading a 16k file.
For the Mono code, they stop the running code, walk the tree, and marshall it into a package and unpack it on the other side. Then they have to run a JIT compiler over the code to reproduce the native code that actually runs. This used to be all done in one operation which is why teleporting and region copying mono scripts was such a load on the sim. I don't remember all the optimizations they've made on this process, but I would definitely describe it as something I'd have no interest in attempting to code.