You can get penalties in a few ways. The most common of these is by running into another driver intentionally (whether actually intentional or not doesn't seem to matter to the in-game stewards). Another common way to get a penalty is to cut a corner, giving yourself an advantage over other drivers.
Just make sure you drive safely and you should be fine with this.
You'll have to get the fastest lap time (the overall lap time will be in purple). You can tell you're doing well if you see the sector times showing in the color purple throughout each lap. If there are no other drivers around you, you should have enough free space to max out your car and drive aggressively. Don't forget to use KERS and DRS when available!