Kikki's Workshop Q&A: Let's ask Kikki ! Kikki's Workshop
Why doesn't the oil in the cylinder of a hydraulic excavator spill ?
When you take a faucet apart, you can see a round rubber seal that keeps water from spilling. The cylinder in a hydraulic excavator does the same thing. The part called "O-ring" prevents oil from leaking, and the part called "urethane seal" prevents soil and other stuff from coming inside.

The cylinder is a shiny silver color because the surface is extremely smooth. Even a small bump on the cylinder can cause oil leak.
*Image of the cut cylinder seen from side. See how tightly it is guarded with O-ring and the seal ?