How can I bootstrap a multi-site instance?
I was able to get this working by setting the server variable  $_SERVER['SCRIPT_NAME'] to '/subsite/index.php' (where /subsite/ is the url path to the subsite). 

$_SERVER['SCRIPT_NAME'] = '/subsite/index.php';

define('DRUPAL_DIR', '/usr/share/nginx/html');
use Drupal\Core\DrupalKernel;
use Symfony\Component\HttpFoundation\Request;

require_once DRUPAL_DIR . '/core/includes/database.inc';
require_once DRUPAL_DIR . '/core/includes/schema.inc';

// Specify relative path to the drupal root.
$autoloader = require_once DRUPAL_DIR . '/autoload.php';
$request = Request::createFromGlobals();

// Bootstrap drupal to different levels
$kernel = DrupalKernel::createFromRequest($request, $autoloader, 'prod');
$kernel-&gt;boot();
$kernel-&gt;prepareLegacyRequest($request);
$em = $kernel-&gt;getContainer()-&gt;get('entity.manager');

$entity = $em-&gt;getStorage('node')-&gt;create(
array(
  'type' =&gt; "article",
  'title'=&gt; "test entity",
  'body' =&gt; "body body body",
));

$entity-&gt;save();