> ## Documentation Index
> Fetch the complete documentation index at: https://novita.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# SSH-toegang

> Je kunt een WebSocket-proxy gebruiken om via SSH verbinding te maken met je sandbox

export const SandboxConfigHint = () => {
  if (typeof document === "undefined") {
    return null;
  } else {
    return <Note>Before running the example code in this document, please ensure you have properly configured environment variables. For details, please refer to <a href="/docs/nl/guides/sandbox-your-first-agent-sandbox#configure-environment-variables">Configure Environment Variables</a>.</Note>;
  }
};

Door SSH te gebruiken, kun je veilig verbinding maken met een externe command-line-omgeving, bestanden overdragen via protocollen zoals SCP of SFTP, en werken met software die afhankelijk is van SSH-gebaseerde verbindingen.

<SandboxConfigHint />

## Snel aan de slag

<Steps>
  <Step title="Bouw de SSH-template">
    Definieer een template die een OpenSSH-server bevat voor SSH-toegang en [websocat](https://github.com/vi/websocat) voor het doorsturen van WebSocket-gebaseerde verbindingen:

    <CodeGroup>
      ```js JavaScript & TypeScript icon="js" theme={"system"}
      // template.ts
      import { Template, waitForPort } from 'novita-sandbox/code-interpreter'

      export const template = Template()
        .fromUbuntuImage('25.04')
        .aptInstall(['openssh-server'])
        .runCmd([
          'curl -fsSL -o /usr/local/bin/websocat https://github.com/vi/websocat/releases/latest/download/websocat.x86_64-unknown-linux-musl',
          'chmod a+x /usr/local/bin/websocat',
        ], { user: 'root' })
        .setStartCmd('sudo websocat -b --exit-on-eof ws-l:0.0.0.0:8081 tcp:127.0.0.1:22', waitForPort(8081))
      ```

      ```python Python icon="python" theme={"system"}
      # template.py
      from novita_sandbox.code_interpreter import Template, wait_for_port

      template = (
          Template()
          .from_ubuntu_image("25.04")
          .apt_install(["openssh-server"])
          .run_cmd([
              "curl -fsSL -o /usr/local/bin/websocat https://github.com/vi/websocat/releases/latest/download/websocat.x86_64-unknown-linux-musl",
              "chmod a+x /usr/local/bin/websocat",
          ], user="root")
          .set_start_cmd("sudo websocat -b --exit-on-eof ws-l:0.0.0.0:8081 tcp:127.0.0.1:22", wait_for_port(8081))
      )
      ```
    </CodeGroup>

    Bouw deze nu:

    <CodeGroup>
      ```js JavaScript & TypeScript icon="js" theme={"system"}
      // build.ts
      import { Template, defaultBuildLogger } from 'novita-sandbox/code-interpreter'
      import { template as sshTemplate } from './template'

      await Template.build(sshTemplate, 'ssh-ready', {
        cpuCount: 2,
        memoryMB: 2048,
        onBuildLogs: defaultBuildLogger(),
      })
      ```

      ```python Python icon="python" theme={"system"}
      # build.py
      from novita_sandbox.code_interpreter import Template, default_build_logger
      from template import template as ssh_template

      Template.build(ssh_template, "ssh-ready",
          cpu_count=2,
          memory_mb=2048,
          on_build_logs=default_build_logger(),
      )
      ```
    </CodeGroup>
  </Step>

  <Step title="Start een sandbox vanuit die template">
    <CodeGroup>
      ```js JavaScript & TypeScript icon="js" theme={"system"}
      import { Sandbox } from 'novita-sandbox/code-interpreter'

      const sbx = await Sandbox.create('ssh-ready')
      console.log(sbx.sandboxId)
      ```

      ```python Python icon="python" theme={"system"}
      from novita_sandbox.code_interpreter import Sandbox

      sbx = Sandbox.create("ssh-ready")
      print(sbx.sandbox_id)
      ```
    </CodeGroup>
  </Step>

  <Step title="Maak verbinding vanaf je lokale machine">
    <CodeGroup>
      ```bash macOS icon="terminal" theme={"system"}
      # Install websocat
      brew install websocat

      # Connect to your sandbox
      ssh -o 'ProxyCommand=websocat --binary -B 65536 - wss://8081-%h.sandbox.novita.ai' user@<sandbox-id>
      ```

      ```bash Linux icon="terminal" theme={"system"}
      # Install websocat
      sudo curl -fsSL -o /usr/local/bin/websocat https://github.com/vi/websocat/releases/latest/download/websocat.x86_64-unknown-linux-musl
      sudo chmod a+x /usr/local/bin/websocat

      # Connect to your sandbox
      ssh -o 'ProxyCommand=websocat --binary -B 65536 - wss://8081-%h.sandbox.novita.ai' user@<sandbox-id>
      ```
    </CodeGroup>
  </Step>
</Steps>

***

## Hoe het werkt

[Websocat](https://github.com/vi/websocat) fungeert als de proxy, en SSH-verbindingen worden via WebSocket doorgestuurd via de blootgestelde poorten van de sandbox.

```
┌───────────────────────────────────────────────────────────┐
│  Your Machine                                             │
│  ┌──────────┐    ProxyCommand    ┌──────────────────┐     │
│  │   SSH    │ ────────────────── │    websocat      │     │
│  │  Client  │                    │   (WebSocket)    │     │
│  └──────────┘                    └─────────┬────────┘     │
└────────────────────────────────────────────┼──────────────┘
                                             │
                         wss://8081-<sandbox-id>.sandbox.novita.ai
                                             │
┌────────────────────────────────────────────┼──────────────┐
│  Novita Sandbox                            ▼              │
│                                  ┌──────────────────┐     │
│                                  │    websocat      │     │
│                                  │  (WS → TCP:22)   │     │
│                                  └─────────┬────────┘     │
│                                            │              │
│                                  ┌─────────▼────────┐     │
│                                  │   SSH Server     │     │
│                                  │   (OpenSSH)      │     │
│                                  └──────────────────┘     │
└───────────────────────────────────────────────────────────┘
```
