             for cb in @_spawn_cbs
                 cb?(err)
         opts = {detached: true, stdio:'ignore'}
+        if @name.indexOf('sage')
+            # special environment for sage-based kernels
+            opts.env = SAGE_JUPYTER_ENV
         if @_directory != ''
             opts.cwd = @_directory
         require('spawnteract').launch(@name, opts).then(success, fail)

iframe = require('smc-webapp/jupyter/iframe')
{remove_redundant_reps} = require('smc-webapp/jupyter/import-from-ipynb')
nbconvert = require('./nbconvert')

exports.jupyter_backend = (syncdb, client) ->
    dbg = client.dbg("jupyter_backend")

        if @_kernel?
            @_kernel.spawn?.removeAllListeners()
            @signal('SIGKILL')  # kill the process group
            try
                fs.unlink(@_kernel.connectionFile)
            catch err
                # ignore
            delete @_kernel
            delete @_channels
        if @_execute_code_queue?
