Tension is an internal force in a body, such as a rope, that resists any attempt to pull the rope apart. Simply, tension arises due to intermolecular interactions, and if it did not exist, ropes would fall apart the moment you pull on them.
Now, it is necessary to distinguish between internal and external forces for a body. External forces are forces that act on the body due to other bodies, such as friction and gravity. When you look at the body as a whole, it is easy to see the effect of the force on the body. External forces allow the bulk of the body to accelerate, provided no other external forces cancel them out (equilibrium). For example: a body acted upon by the Earth's gravity:
Internal forces of a body are different. Internal forces exist inside a body, and the effects of internal forces cannot directly interact with anything external to the body. In other words, internal forces are forces that one part of a body causes onto another part of the same body (see later). Hence it is not as clear to see the "direction" of such forces. Internal forces do not lead to bulk acceleration, but instead cause body deformation (e.g. stretching a spring, or bending a ruler). Here is a diagram showing the internal forces acting on a block:
Well, you can't see anything obvious on the outside, but that not because internal force don't exist. It's because if you were to take all of the internal forces present in a body, they would sum to zero. This is a result of Newton's 3rd Law. Instead, a better way to visualise internal forces in a body is to make an imaginary cut through the body and see how the forces act on the cut face. This is better demonstrated below in the diagram, where a rope is being pulled apart:
By considering an imaginary cut, you look at the two halves and enforce equilibrium (if the whole rope obeys equilibrium, so must any arbitrary sub-length of rope). By doing so, you find out that in order to satisfy equilibrium, one half must exert a force on the other, and vice versa by Newton's 3rd Law. These particular forces are internal since they're forces caused by one part of the rope acting on another part of the same rope. These internal forces act at the interfaces of the imaginary cut, and, in this case, are known as the tension. To be more precise, it is the tension at the location on the rope where the imaginary cut is made. Note that you can determine the tension's direction if you look at one half of the rope, but since the tensions occur in pair, there is no obvious direction of tension at that point of the rope for the whole rope.
Looking at your example, let's make a few cuts to see the tension forces in the rope:
Only the forces acting on/in the rope, on the box or on the hanging mass are included in the diagram above.
In short, internal forces like tension at a particular point in a rope doesn't really have a clear cut direction, as they occur in pairs.