Before I compute, let me say what the object is. Scale is irrelevant to a shortest-path question, so I will take the cube to be a unit cube sitting on nought to one in each direction.
The ant is at the origin and wants the vertex diagonally opposite in space, the point one, one, one. The whole difficulty is the constraint: it can only walk on the faces, so it may not use the straight line through the middle.
My goal is a genuine minimisation: shorten the curve among all paths that stay glued to the surface.
Here is the key idea, and it is the thing this question is really testing. On a single flat face the shortest route is obviously straight, and the surface only bends where faces meet at an edge. So if I cut along edges and lay the relevant faces flat, a candidate shortest path turns into a straight line in the plane.
So I do not want to write down a 3D arc-length integral. I want to flatten. That dimensional reduction is the move.
Now, which faces can the ant use? A lies on three faces, the ones where a coordinate is nought; B lies on the three where a coordinate is one. To get from A to B crossing just one edge, I pick one face from A's triple and one from B's triple, but the two have to actually share an edge. The only forbidden choice is the parallel pair. Three by three is nine, minus three parallel pairs, gives six candidate nets.
Let me draw one of the six nets concretely. I keep the bottom face, through A, fixed, and I swing the right-hand face up about the edge they share. Both are unit squares, so together they are a two by one rectangle.
In that rectangle A lands in the bottom-left corner and B lands in the top-right corner. The shortest path in the plane is the straight line, and its length is the hypotenuse of a two-by-one right triangle: root of four plus one, which is root five.
Note this: that straight line cuts the shared edge at its midpoint, at height one half. That is the fold-back point: it says on the real cube the ant goes in a straight line on the bottom, crosses the edge exactly in the middle, then goes straight on the side face.
So the candidate answer is root five, about two point two three six. To see it another way: the diagonal is split by the midpoint into two equal legs, each of run one and rise one half, so each is root one and a quarter, about one point one one eight, and twice that is root five.
But I do not want to accept one lucky drawing. Two things need checking: first, that among paths crossing this one edge the midpoint really is the shortest, and second, that no other unfolding beats it. So a numerical check, then a comparison.
Let me sweep the crossing point by hand instead of trusting the picture. If the ant crosses the shared edge at height t, the path is two straight segments: one of length root of one plus t squared, and the other of length root of one minus t, squared, plus one.
Now I read values: at t equals nought it is two point four one four; nudge to a quarter, two point two eight one; at exactly one half it drops to two point two three six, which is root five; then it climbs back up to two point four one four at t equals one. Symmetric, with a clean minimum in the middle, so the midpoint is genuinely the minimiser, not my drawing bias.
And a sanity bracket. The straight line through the solid is root three, about one point seven three two, but that is illegal because it goes through the interior, so it is only a lower bound. Walking the three edges costs exactly three, an upper bound. Root five is in between, which is where a legal surface path has to live.
Now why is this the true answer rather than just a short path? Any shortest surface path is a geodesic, and a geodesic, once you unfold exactly the faces it crosses, is a straight segment. So the global minimum is the smallest net diagonal over every legal face sequence. I have reduced an infinite-dimensional problem to comparing finitely many rectangles.
Two-face nets give root five, two point two three six. There is no shorter candidate: unfold whatever faces the walk uses and the target lands on an image at least that far from the start, so root five is the minimum and the six nets above all tie. The visible competitor is the route that corners through a vertex of the solid, one face diagonal plus one edge, root two plus one, about two point four one four - strictly longer, and all six of those agree by symmetry. So two faces is optimal.
And because the two endpoints are space-diagonal opposites, there is nothing special about which coordinate is which, so all six two-face nets are congruent, and all six give the same root five.
Let me get the number a second, independent way, by folding the path back onto the solid and measuring with 3D vectors, never touching a net.
The path goes from A to the midpoint of the edge where the bottom face meets the vertical face through B, the point one half, one, nought, and then to B at the point one, one, one. The first segment vector is one half, one, nought, of length root of one quarter plus one, that is root one and a quarter. The second is one half, nought, one, the same root one and a quarter.
Two times root one and a quarter is root five, two point two three six. This matches the flat unfolding exactly, and it also confirms the route is legal: each segment lies flat in one face and they only meet on the shared edge.
So for the unit cube the shortest surface walk is root five, and for a cube of side s it is s root five.
The square root was never the point: for a rectangular box the same flattening gives three genuinely different nets, and the answer is the least of three quantities: a plus b, squared, plus c squared, all under one root; a plus c, squared, plus b squared, all under one root; and b plus c, squared, plus a squared, all under one root.
And the interesting part is where the obvious choice fails. Take a box with a square base a and height h. If you go around the side faces you get four a squared plus h squared under a root; if you cut over the top you get a plus h, squared, plus a squared, under a root. Those two are equal exactly when h equals a, that is, the cube. Make the box flat, height below a, and the over-the-top route is shorter; make it tall and the around-the-sides route wins. Numerically, at height nought point five the top route is one point eight zero three against the sides' two point zero six two; at height one point five it flips, sides two point five beating top two point six nine three. The cube sits precisely on the crossover.
If you want the structure rather than the single number: there are six shortest paths, not one. They are the six two-face nets, all congruent, all root five, permuted by the rotations that hold the diagonal from A to B fixed.
Each one crosses a single edge at its exact midpoint, and no shortest path ever re-enters a face it has already used. That last fact is why the check reduces to finitely many nets: on a convex solid, a geodesic that revisited a face could be shortened, so it would not have been minimal to begin with.
I offer this as a bonus; the question only asked for the shortest length.
Then it becomes a graph shortest-path problem on the cube's twelve edges, and the answer changes completely. From A to the opposite vertex you must change all three coordinates, and each edge moves exactly one coordinate, so you need at least three edges. Three edges of unit length give exactly three.
So restricting the ant to edges inflates the path from root five, about two point two three six, up to three. That is precisely because the diagonal across faces is the saving the surface gives you.
Let me not eyeball it, let me use the formula. The three nets are root of the quantity 3 plus 3, squared, plus 1 squared, which is root 37, about six point zero eight three, and two copies of root of the quantity 3 plus 1, squared, plus 3 squared, which is root 25, exactly five.
So the shortest is five, not six point zero eight. The 'obvious' route that wraps around the two big faces is the longest one. For a flat box you want to cross the short dimension on the way, which is the failure case I flagged when generalising.
Because the only thing that could make it illegal is if it left the two faces, but a straight segment inside the net rectangle stays inside, and the net is exactly those two faces. Where the segment crosses the shared edge, folding maps the two half-segments onto the two real faces meeting along that edge.
The fold preserves length on each face because it is a rigid rotation, and the two images agree at the crossing point since it lies on the seam. So the folded path is continuous, lies on the surface, and has the same length, root five.
No. Restricted to any single face, the face is flat, so the shortest connection between the two points where the path enters and leaves that face is the straight segment, and any curve there is longer. A shortest path has to be piecewise straight, and it bends only at edges.
That is why I only ever compare straight segments in nets: I am not assuming the answer is straight, I am proving each piece of a minimal path must be straight.