I am working on a castle build and mobs keep spawning in the area. I know that using lamps work. but is there away to use commandblocks to stop the spawning around the area but still keeps mob spawning on the outside.
You can teleport mobs within a certain distance of the point or within a certain box into the void.
Unless you want to remove all entities except players, including minecarts, item frames etc, you'd need one command block per mob type (zombie, spider etc).
/tp @e[type=zombie] ~ -10 ~
or you could teleport them somewhere else if you wanted the drops or to fill up the mob cap and stop more from spawning, but repeating command blocks should remove them fast enough that you didn't notice them.