As mentioned already, the metric to use is called the intrinsic metric, but without having worked with it before, it might be hard to use.
This is a good example to start using the intrinsic metric on though.
Let us label the four walls, ceiling, and floor as $N,E,S,W,C,F$ respectively.
Suppose that the ant is currently on the western wall. You have then the following space: (ignore the arrows for now)
$$\begin{array}{|c|c|c|c|c|}
\hline
&&\exists&\color{orange}{\swarrow}\\
\hline
\color{green}{\swarrow}&&C&\color{red}{\searrow}\\
\hline
E&S&W&N&E\\
\hline
&\color{blue}{\nearrow}&F\\
\hline
&&\exists&\color{orange}{\swarrow}\\
\hline
\end{array}$$
where $\exists$ denotes the eastern wall, but oriented differently as suggested by the picture..
Similar images can be made for the ant's current location, but they are difficult to superimpose in a 2-dimensional setting.
Given a starting location and an ending location, you can then find the shortest path to be the same as the shortest path on one of these pictures. For example, if you wish to begin at the bottom left of the western wall and wish to end at the top right of the northern wall, i.e. starting at the corner where the blue $\color{blue}{\nearrow}$ is pointing and ending at the corner where the red $\color{red}{\searrow}$ is pointing, you will travel from the starting corner to the midpoint of the shared edge between the western and northern wall, and then continuing along the northern wall to the final corner.
However, note that the red $\color{red}{\searrow}$ is pointing to the exact same point as the green $\color{green}{\swarrow}$, and so the ant could have chosen to go counterclockwise as opposed to clockwise by traveling from the starting vertex along a straightline path to the midpoint of the shared edge between the southern and eastern wall before continuing to the top left of the east wall (which is the same as the top right of the north wall). Similarly, the additional orange arrows also point to the same spot and so he could have traveled along the ceiling or floor to get to his destination.