First, there are multiple ways to "move" your actors. How to make your actor move backwards depends on which technique you use to move it.
Unless your world is unbounded, your actors will automatically be prevented from moving past any edge of your world. So, if moving in any one of the four cardinal directions (horizontally or vertically), you actor will stop at any edge. Then, it location (x- or y-coordinate value) can be used as a condition to change directions.