Docs

Toolchains

How Alien compiles and packages your code for each platform.

The .code() method on a Function tells Alien where your source code is and how to build it. There are two approaches: point at source code with a toolchain, or use a pre-built container image.

Source Code

Point at a directory and pick a toolchain. Alien compiles, packages, and creates an OCI image automatically.

TypeScript

new alien.Function("api")
  .code({
    type: "source",
    src: "./api",
    toolchain: { type: "typescript" },
  })
  .build()

Alien detects your package manager (bun, pnpm, or npm), installs dependencies, and compiles to a single executable using bun build --compile. The output is a standalone binary — no node_modules, no dist/ folder.

Use any HTTP framework (Hono, Express, Fastify). Export your app as the default export:

import { Hono } from "hono"
const app = new Hono()
app.get("/health", (c) => c.json({ ok: true }))
export default app

Options:

OptionDefaultDescription
binaryNamepackage.json nameName of the compiled binary.

Rust

new alien.Function("agent")
  .code({
    type: "source",
    src: "./agent",
    toolchain: { type: "rust", binaryName: "my-agent" },
  })
  .build()

Alien builds with Cargo using cross-compilation for the target platform. For Linux targets, it uses cargo-zigbuild (Zig as the C toolchain for musl targets). The output is a single statically-linked binary.

Options:

OptionDefaultDescription
binaryNamerequiredName of the binary to build (the Cargo binary target).

Docker

new alien.Function("service")
  .code({
    type: "source",
    src: "./service",
    toolchain: { type: "docker" },
  })
  .build()

Alien builds using docker buildx with multi-architecture support. Use this when you need full control over the build process or have dependencies that don't fit the TypeScript/Rust toolchains.

Options:

OptionDefaultDescription
dockerfile"Dockerfile"Path to the Dockerfile, relative to src.
buildArgs{}Build arguments passed to docker build.
targetMulti-stage build target.
// Custom Dockerfile with build args
.code({
  type: "source",
  src: "./service",
  toolchain: {
    type: "docker",
    dockerfile: "Dockerfile.prod",
    buildArgs: { NODE_ENV: "production" },
    target: "runtime",
  },
})

Pre-Built Image

Skip the build entirely and use an existing container image:

new alien.Function("api")
  .code({ type: "image", image: "ghcr.io/myorg/myimage:latest" })
  .build()

The image is pulled and deployed directly. Use this when you build images in your own CI/CD pipeline or want to use a third-party image.

On this page