Is it just a straight line between A and B?
If so you can limit another objects position between them with:
T=clamp(((b.x-a.x)*(sprite.x-a.x)+ (b.y-a.y)*(sprite.y-a.y))/((b.x-a.x)^2+ (b.y-a.y)^2),0,1)
X=lerp(a.x,b.x,t)
Y=lerp(a.y,b.y,t)
That formula is a vector projection.
If the path isn’t straight then you’ll have a series of lines. For that you’ll need to incrementally find what line segment to limit the sprite’s position to.