Is it possible in any way to write a code, in game, and them execute it? The aim is to allow the player to mod the game.
I program in C# and i have already a little experience with Unity (especially multiplayer games).
So it depends on your game’s platform:
Web player/iOS - you would probably have to build your own scripting language that was interpreted and executed by your game engine. You cannot emit or compile code on these platforms.
PC/Mac - you can probably get System.Reflection.Emit to create .NET IL assemblies at run time from script typed in - by I doubt the C# compiler services are shipped with Unity by default so you’d probably need to build those in a separate assembly using MonoDevelop and then link it into your game.
Console - no idea
It would be pretty hard work - I’d look for a C# open source C# prep/compilation project and try to link with that if you are targeting PC/Mac standalone.