It may be some settings in Sonar that are producing this delay, or it may be caused by one or more effects in a given project, or a combination of both.
Try the following settings for recording in Sonar:
Audio interface: Sample Rate 48 k, ASIO Buffer of 128
Sonar: Driver Mode of ASIO, Sample Rate of 48 k, Record Bit Depth of 24 bits.
The above is based on your having an audio interface. IF you do not have an audio interface, I urge you to consider getting one.
You want to end up with a combination of settings that give you a Sonar-reported Total Roundtrip Latency of around 10 milliseconds, or just a little under that. This will greatly reduce lag/latency when trying to record, such as the problems you are reporting.
Once you apply the above settings, try them out in a project without any effects, just to make sure it all plays OK in as simple a project as possible.
It is important to understand that certain effects, by design, add MASSIVE latency to projects, and are NOT meant to be loaded into projects while recording. These effects are instead meant for mixing/mastering, and will require the ASIO Buffer Size to be set WAY higher than for recording (1024 is common). Effects such as Perfect Space and Boost 11 are examples of effects that add lots of latency, and are not meant to be used during recording.
So, try out the settings and post back. :)
Bob Bone