A spacecraft that is propelled by a rocket can shrink its orbit, and thus move closer to the sun, by thrusting the rocket in the opposite direction as the spacecraft's motion. Similarly, if a solar sail can produce thrust in the opposite direction as the spacecraft's motion, its orbit will also shrink. By producing thrust in the same direction as the spacecraft's motion, the orbit will expand, and the spacecraft will move farther away from the sun. A rocket can thrust opposite its motion by pointing the rocket engine forward along the path of its motion. This produces a force from the rocket engine that is in the opposite direction as the spacecraft's motion.
Solar sails are more complex.
The force produced by sunlight on a solar sail is the addition of the forces from the incoming sunlight and the reflected sunlight. This force always points away from the sun, and is at an angle that is close to a right angle to the surface of the sail. If this force is angled back along the solar sail's path, the spacecraft's orbit will start to shrink, bringing it closer to the sun. If the force is angled foreward along the spacecraft's path, the orbit will grow and the solar sail will head farther from the sun. In real practice, the behavior of a solar sail is more complicated because sunlight pushes not only along the spacecraft's orbit, but also straight out from the sun.