The operative word is 'within' a particular territory.
It means that, say, a Chinese cargo ship cannot carry goods from Kuantan to Kota Bahru or from Kuching to Labuan, though it may carry Chinese goods from China to a Malaysian port. In other words, carriage within the territory of a country is not permitted to a foreign ship.
Previously, the Malaysian cabotage policy forced foreign ships to carry goods to ONLY Port Klang, from where Malaysian cargo ships then carry or distribute the goods to various places such as Sandakan, Labuan, Tawau, etc. This is wrong interpretation of cabotage, and smacks of empire building.
Why only Port Klang? If the ship comes from Japan it should be allowed even under cabotage policy to off load goods at principal (officially designated) ports like Sandakan, Labuan, Kuching, Kuantan, Kota Bahru, Port Klang, Penang.
It cannot take goods from Sandakan to Labuan or from Port Klang to Penang, but it can offload say, cars and vehicles from Japan at both Port Klang and Penang.
Pick up goods from Port Klang to offload at Penang is a no-no, but offloading goods from Japan at both Port Klang and Penang should be okay. That would be the job of port officials and customs to ensure.
So cabotage is about protecting domestic routes for only domestic ships, airlines, etc.
Some countries like Singapore has bugger all reason to impose cabotage, wakakaka.