Is there a way to export code for an arduino even as a hex file?
Perusing the source code of the Arduino bootloaders at https://github.com/arduino/Arduino/tree/master/hardware/arduino/bootloaders it appears that they do in fact support the stk500 readback functionality for flash memory, such that you can accomplish your goal with a client program such as avrdude.
So the answer to the question is that if you can access the bootloader, then yes you can read out the contents of the flash memory in a binary or hex format, without resorting to an external programmer.
If you cannot access the bootloader (reset troubles, or no intact bootloader present) then you may be able to do so with an external programmer, provided security fuse settings do not prevent this.
Yes, I have successfully pulled the boot kernel from one Arduino Board via ISCP and pushed it into another. The security fuses were not set. where avrdude will work. Back then I used AVR Studio with a STK500 as it had a GUI and I did not need to learn all the avrdude switches. Either will work.
Setting the fuse defeats open source. That said the boot kernel is provided in the IDE. ..\Arduino\hardware\arduino\bootloaders\atmega8\ATmegaBOOT.hex along with others variant chips.