The gravitational force of the sun provides the necessary centripetal force to keep the earth in its orbit. This counters by the centrifugal force which arises due to the circular motion of the earth. Thus, These force balances each other at after every instant so the earth remains in its orbit without either falling into the sun or going away tangentially to its orbit.