Answer
F acts in positive $x$ direction
Work Step by Step
Work done by the force is is equal to negative change in potential Energy
:
$W=-\Delta U=-\left( U_{B}-U_{A}\right) =-20J=F\times \Delta x=F\times \left( 2-4\right) =F\times \left( -2\right) \Rightarrow$
This leads to: $ F=10N$
We see that $F$ is positive so it acts in positive $x$ direction.