If you are asking the rules, I'm afraid, it'll be too broad here to describe. However, in the context of the sentence in concern, I can give you some idea. You would be, possibly, able to determine the use of prepositions then.
The gift is in the box - You have to open the box or at least take out that gift from the box. In short, if the box is not transparent, you cannot see the gift. It is inside the box.
The gift is on the box - Probably, the gift is lying on the box. Imagine a gift on the table which means the gift is lying on the table. In the same way, the gift is on the box i.e. on the surface of box.
At talks about the place the thing/person is at. For instance, I'm at office means your location is office. In this sense, The gift is at the box will be bad English.
Another important rule in the context of time is...
Use on to indicate date or day - The party is on Tuesday
Use in for the month - My birthday is in October
Use at for the hours - I'll meet you at 6 o'clock.