Convert a Serial string to a sketch command on Yun?
There is a third option: install an interpreter on the Arduino, then
just send it the program you want it to run. There are a few such
interpreters available. A quick search showed:


Bitlash, a C-like language
iArduino, another
C-like language
FlashForth, a
Forth
implementation
FINF Is Not Forth, a Forth-like
language


There are probably many others.

The difference between this option and Majenko's option 2 is that this
would allow you to send a complete program, with functions,
conditionals, loops, etc., whereas with a Firmata or similar approach
you would keep the program logic (functions, loops, conditionals) on the
host computer, and only send simple commands to the Arduino.