> ## 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.

# Erstellung

## Basis-Image

Jedes Template beginnt mit einer Quellumgebung. Das SDK unterstützt mehrere Einstiegspunkte, je nachdem, wie viel Kontrolle du benötigst.

* `fromPythonImage(...)` / `from_python_image(...)` für eine Standard-Python-Laufzeitumgebung
* `fromUbuntuImage(...)` / `from_ubuntu_image(...)` oder `fromDebianImage(...)` / `from_debian_image(...)` für eine Standard-Linux-Basis
* `fromNodeImage(...)` / `from_node_image(...)` und `fromBunImage(...)` / `from_bun_image(...)` für sprachspezifische Basen
* `fromImage(...)` / `from_image(...)` für ein beliebiges Container-Image
* `fromDockerfile(...)` / `from_dockerfile(...)` wenn dein Dockerfile bereits die maßgebliche Quelle ist
* `fromBaseImage()` / `from_base_image()` um mit der Standardbasis der Plattform zu beginnen
* `fromTemplate(...)` / `from_template(...)` um auf einem anderen Template aufzubauen

`fromPythonImage("3.12")` und `from_python_image("3.12")` entsprechen dem Start mit:

```dockerfile Dockerfile icon="docker" theme={"system"}
FROM python:3.12
```

## Private Registries

Wenn sich dein Basis-Image in einer privaten Registry befindet, übergib beim Definieren der Template-Quelle Anmeldedaten.

Die JS- und Python-SDKs unterstützen:

* generische Registry-Anmeldedaten mit Benutzername und Passwort
* AWS-Registry-Anmeldedaten
* GCP-Registry-Anmeldedaten
* Huawei-Cloud-Registry-Anmeldedaten

Beispiel für eine generische private Registry:

<CodeGroup>
  ```ts JavaScript & TypeScript icon="js" theme={"system"}
  import { Template } from "novita-sandbox"

  const template = Template().fromRegistry(
    "registry.example.com/team/myimage:latest",
    {
      username: process.env.REGISTRY_USERNAME,
      password: process.env.REGISTRY_PASSWORD,
    }
  )

  const build = await Template.build(template, "my-private-image-template")
  console.log(build.templateId)
  ```

  ```python Python icon="python" theme={"system"}
  import os

  from novita_sandbox.core import Template

  template = Template().from_registry(
      "registry.example.com/team/myimage:latest",
      username=os.environ.get("REGISTRY_USERNAME"),
      password=os.environ.get("REGISTRY_PASSWORD"),
  )

  build = Template.build(template, "my-private-image-template")
  print(build.template_id)
  ```
</CodeGroup>

## Template definieren

Mit der Builder-API kannst du die finale Umgebung direkt im Code zusammenstellen. Häufige Definitionsschritte sind:

* `runCmd(...)` / `run_cmd(...)` zum Installieren von Paketen oder Ausführen von Provisioning-Befehlen
* `copy(...)` zum Einbinden lokaler Dateien
* `makeDir(...)`, `remove(...)`, `rename(...)` und `makeSymlink(...)` zur Gestaltung des Dateisystems
* `setEnvs(...)` / `set_envs(...)` für Umgebungsvariablen
* `pipInstall(...)`, `npmInstall(...)`, `bunInstall(...)` und `aptInstall(...)` für die Paket-Einrichtung
* `gitClone(...)` / `git_clone(...)` um Code in das Image zu bringen

Beispiel:

<CodeGroup>
  ```ts JavaScript & TypeScript icon="js" theme={"system"}
  import { Template } from "novita-sandbox"

  const template = Template()
    .fromPythonImage("3.12")
    .setWorkdir("/app")
    .setEnvs({
      APP_ENV: "production",
      PORT: "8000",
    })
    .runCmd("pip install fastapi uvicorn")
    .copy("app.py", "/app/app.py")
  ```

  ```python Python icon="python" theme={"system"}
  from novita_sandbox.core import Template

  template = (
      Template()
      .from_python_image("3.12")
      .set_workdir("/app")
      .set_envs(
          {
              "APP_ENV": "production",
              "PORT": "8000",
          }
      )
      .run_cmd("pip install fastapi uvicorn")
      .copy("app.py", "/app/app.py")
  )
  ```
</CodeGroup>

## Start- und Bereitschaftsbefehle

Verwende einen Startbefehl, wenn das Template im Build-Ergebnis einen langlebigen Dienst starten soll, und verwende einen Bereitschaftsbefehl, um festzulegen, wann dieser Dienst als fehlerfrei gilt.

Das ist nützlich für Web-Apps, API-Server, Background-Worker und jedes Template, das bereits initialisiert sein soll, wenn eine Sandbox startet.

<CodeGroup>
  ```ts JavaScript & TypeScript icon="js" theme={"system"}
  import { Template } from "novita-sandbox"

  const template = Template()
    .fromPythonImage("3.12")
    .runCmd("pip install fastapi uvicorn")
    .copy("app.py", "/home/user/app.py")
    .setStartCmd(
      "uvicorn app:app --host 0.0.0.0 --port 8000",
      "python - <<'PY'\nimport urllib.request\nurllib.request.urlopen('http://127.0.0.1:8000', timeout=2)\nPY"
    )
  ```

  ```python Python icon="python" theme={"system"}
  from novita_sandbox.core import Template

  template = (
      Template()
      .from_python_image("3.12")
      .run_cmd("pip install fastapi uvicorn")
      .copy("app.py", "/home/user/app.py")
      .set_start_cmd(
          "uvicorn app:app --host 0.0.0.0 --port 8000",
          "python - <<'PY'\nimport urllib.request\nurllib.request.urlopen('http://127.0.0.1:8000', timeout=2)\nPY",
      )
  )
  ```
</CodeGroup>

Du kannst die Bereitschaft auch separat mit `setReadyCmd(...)` / `set_ready_cmd(...)` konfigurieren.
