Simple Inverse Kinematics for a slider?
Tell me if this is ok for you:


Create 2 objects: Your cube and your cylinder
Create 1 armature with a small vertical bone for the cube and a long horizontal bone for the cylinder.
Parent the small cube to the long with a ctrl P > Keep Offset.
In Pose mode, give a Bone Constraint > Limit Location to each bone, choose Local Space and click every axis that should be limited.
Now when you move your cylinder bone it should only go up, and the cube bone should follow it and be constrained in its axis