Why did God allow the Israelites to commit actions which are clearly wrong, by His command, such as allowing daughters to be sold into slavery (Exodus 21:7) or committing genocide upon the peoples of Canaan (Joshua)? If the Bible is infallible, is this the kind of moral code that God wants us to apply to our lives?
It is interesting when atheists attempt to use the Bible against itself. To make your argument, you are admitting that there is a moral code that the Bible upholds. What you are hoping to find is a place where it is inconsistently applied.
While you refer to a part of a rule regulating slavery, you did not investigate why slavery existed. Even the definition of slavery is vastly different from our view of it today. The most common cause was what we would call "bankruptcy" when someone overextended his credit and could not pay it off. Possessions would then be sold and if that wasn't enough then members of the family and the person himself would be put into slavery to pay off the debt. The length of servitude would be balanced against the debt. The only catch in the Israelite's system is that an Israelite could not be held in slavery for more than seven years; thus, there was an upper limit on what could be extracted from a "bankruptcy." The reason family members were involved is because they benefited from the money loaned, so they had to help pay off the debt.
The reason American slavery was so bad is that it wasn't connected to what a person did or did not do. People were made slaves simply because of whom they had as parents. Nor were there limits or reasonable terms for ending a period of slavery.
The killing of innocents has always been wrong. "Whoever sheds man's blood, by man his blood shall be shed; for in the image of God He made man" (Genesis 9:6). However, the destruction of the Canaanites was not because the Israelites were better people or that God wanted the space. God promised Canaan to Abraham and his descendants, but He stated it would be a while, "But in the fourth generation they shall return here, for the iniquity of the Amorites is not yet complete" (Genesis 15:16). It was for the nations' sins that they were destroyed. "Do not think in your heart, after the LORD your God has cast them out before you, saying, 'Because of my righteousness the LORD has brought me in to possess this land'; but it is because of the wickedness of these nations that the LORD is driving them out from before you. It is not because of your righteousness or the uprightness of your heart that you go in to possess their land, but because of the wickedness of these nations that the LORD your God drives them out from before you, and that He may fulfill the word which the LORD swore to your fathers, to Abraham, Isaac, and Jacob. Therefore understand that the LORD your God is not giving you this good land to possess because of your righteousness, for you are a stiff-necked people" (Deuteronomy 9:4-6).
What you have missed is that the destruction was punishment for sin, something that God has always done when necessary.