Biological sex is most often male or female, but not always. People can be born intersex (with genitalia that are neither clearly male nor female, which is often “corrected” surgically at birth, and/or with genitalia that don’t match what’s expected from their chromosomes, and/or with chromosome combinations other than XX or XY). Chimerism can result in different parts of the body having different sex chromosomes. It’s not strictly monolithic or binary.
That aside, yes, “sex” broadly refers to biology in some way, though often oversimplified, while “gender” refers to identity and expression (which also don’t necessarily go hand in hand).