There won't be any native Cocoa API's to specifically ask if you are running in a virtual machine vs real hardware.
However, if you know the potential environments you are running under you should be able to use IOKit to query the hardware of the virtual machine.
Virtual Machines will have considerably different hardware than a real Mac so you should be able to detect a real Mac vs a VM based on hardware configuration.
I can not give you any direct code, however, there is a section on Apple's site that discusses accessing hardware with IOKit in general:
IOKit is an advanced subject so if you do not have a lot of experience with the lower-level APIs you may find it a bit confusing as compared to Cocoa.