It looks like you are creating the cuboid in the XY plane and then translating it vertically by the calculated Z value, which doesn’t take into account the slope of the pipe. So you could try to figure out the rotation of the pipe and rotate the cuboid to match, but I would just use the Curve.CoordinateSystemAtParameter node and save yourself some work. Quick example attached.
CuboidByCoordinateSystem.dyn (29.1 KB)