How can I upload a sketch to Arduino UNO via serial?

I'm trying to make a really simple program runner. I'm making this because I want to run programs without overwriting the flash.

How can I send a compiled sketch to my Arduino UNO via serial without overwriting the flash?

You can't. Where should it be stored if not in flash?
But I don't really understand what you want to do.

The Arduino UNO will receive compiled code and the sketch will run it. The code will be stored in a variable.

What kind of code should that be? And what kind of sketch? Do you want to write an interpreter?

What kind of variable should that be? The AVR is not able to run native code that is stored in RAM. Data storage and code storage is strictly separated in AVR ( It's an Harvard architecture ).

I didn't think about creating an interpreter.
How can I do that?

Do what? Writing an interpreter? That maybe a complex task. Depends on the language you want to interpret. May even be too complex for an UNO. Or you define a very simple language that is adapted to your problem.

Can I interpret compiled code?

Strange idea to have a CPU interpret it's own native code by software ...

Maybe it would be a solution to use another kind of processor, that is able to run code from its RAM.

I want the CPU to run code that is received from a device via serial. I don't want to overwrite the flash

May be that you want that, but an AVR is not able to do that.

There exist Forth and Basic-like interpreters.

The more capable ARM-based Arduino boards can run MicroPython or CircuitPython.