Is it possible to format the input from the serial monitor?

You can get it to print out however you want. Are you hoping to have something execute it as code? That's a completely different story.

Yes I am wanting to send the string to an Arduino NanoESP32 running MicroPython to be executed.