Is it possible to eg. create a file using CreateFile, put some code in it and then compile it in running os?
You're asking for too much. Cosmos isn't a full-featured operating system where you have one method to _compilate_ code. To compile code on your os you would need to either write a compiler for the language you want in the kernel directly, or create your own language that would run on your os and write the compiler in it.