These are called tax treaties - each individual treaty has some different rules regarding where incomes are earned and where taxes are owning. As an example, here is one between Thailand and Canada:
The U.S. and China both offer an expatriate exemption (first $100k in income for the US) and foreign tax credits against U.S./China taxes for local country income taxes paid.