According to my tests, you need to double every {. Doubling } also leads to incorrect results. Example: @set foo=a{{$bar}b. But is that all? Please document this (probably here), as I couldn't find anything about it.
There should be a way to escape %, because, if what's written between two instances of this character is the name of an environment variable, this text is replaced.