A variation of frobs idea:
Perhaps you can hard code the edge cases, and dynamically generate the easy cases where the ship/target are not near the edges?
You might also consider not using a curve, maybe doing it via physics? A steering system that considers the edges as something to avoid would do their best to not touch them. Though you do run into a problem where the object might not always make it perfectly to the point. (Which you can kind of fake if you really need it.)
How are you determining the curve? If you have points you know you want the thing to pass through, you could try catmull-rom, and then it's pretty easy to ensure that the catmull-rom control points are clamped to be inside the blue rectangle, which would mostly get you the curve you want. (Not perfect, you'd still run into cases where you might go outside)
Another thing you might want to do, is instead of using some sort of parameterized curve, use a Dubin's Curve instead, and adjust start angle or the min radius as necessary so that the curve doesn't go outside the bounds.