Do you want to actually create an AnimationClip object at runtime?
The easiest way to do this sort of thing in code is by using Mathf.Lerp (Linear Interpolation) and a timer, or using Mathf.SmoothStep which gives you a non-linear movement that speeds up and slows down to create a more organic looking animation path.
The curve would have two Keyframes at each extreme end of the animation.
Then assign the Clip to an Animation object, and use Animation.Play. Don’t forget to name your clip so that you can use the name in the call to Play.