Create an external form to launch a search
The reason was that my form was missing qfKey. This is a CSRF key generated as part of QuickForm forms.
This key must be generated for the particular form in use. By using XDebug in Vim, I was able to find out that the form name must be CRM_Contact_Controller_Search, and that it expects a sequence number too.
So my form is generated as follows:
&lt;?php
// ...
civicrm_initialize();                                                                
$qfKey = htmlspecialchars(CRM_Core_Key::get('CRM_Contact_Controller_Search', 1));    
$mySearchForm = &lt;&lt;&lt;HTML                                            
                                                                                     
&lt;form action=&quot;/civicrm/contact/search/advanced&quot; method=&quot;post&quot;&gt;
  &lt;div&gt;
    &lt;label&gt;Search name or email                                                 
      &lt;input type=&quot;text&quot; name=&quot;sort_name&quot; accesskey=&quot;q&quot; /&gt;         
    &lt;/label&gt;
    &lt;input type=&quot;hidden&quot; name=&quot;hidden_location&quot; value=&quot;1&quot; /&gt;                         
    &lt;input type=&quot;hidden&quot; name=&quot;hidden_custom&quot; value=&quot;1&quot; /&gt;                           
    &lt;input type=&quot;hidden&quot; name=&quot;qfKey&quot; value=&quot;$qfKey&quot;/&gt;                               
    &lt;input type=&quot;hidden&quot; name=&quot;_qf_Advanced_refresh&quot; value=&quot;Search&quot; /&gt;               
  &lt;/div&gt;                                                                                                                
&lt;/form&gt;          
HTML;                                                                    

Posting here as it took me ages to figure out!