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

> ## Agent Instructions
> Automate.ax automations are TypeScript programs.
> Use Bun for installation and command examples.
> Use Automate.ax for the product name and automate.ax for the package, CLI, and domain.
> Treat documented public APIs as current; do not invent transitional or deprecated names.

# Bun runtime

> Understand the Bun 1.4 environment used by deployed custom actions.

Automate.ax runs deployed project code on a pinned Bun 1.4 runtime for ARM64 Linux. You can use Web APIs, Bun APIs, Node.js-compatible APIs, and packages from the `npm` registry inside custom action handlers.

## Choose between Web APIs, Bun APIs, and packages

* Use standard Web APIs such as `fetch`, `Request`, `Response`, `Blob`, streams, and Web Cryptography APIs when they cover the task.
* Use [Bun's built-in runtime APIs](https://bun.com/docs/runtime) for files, image processing, Markdown, hashing, compression, and other common server-side work. The [Bun 1.4 release notes](https://bun.com/blog/bun-v1.4) list the APIs available in this runtime.
* Install packages from the `npm` registry when you need another library. Bun supports ESM, CommonJS, Node.js module resolution, and many `node:*` APIs, but it isn't completely compatible with Node.js. Check [Bun's Node.js compatibility table](https://bun.com/docs/runtime/nodejs-compat) when a package depends on a specific Node.js API.

Prefer a Bun built-in when it avoids an external binary or native add-on. Packages that need a separate executable or a runtime-specific native add-on may not work in the Linux ARM64 deployment environment.

## Install dependencies and types

Install and lock every imported package before deployment:

```bash theme={null}
bun add package-name
```

Automate.ax bundles imported dependencies into the deployment. The production runtime doesn't install missing packages.

When you use the `Bun` global, install its TypeScript definitions:

```bash theme={null}
bun add --dev @types/bun
```

TypeScript 6 and later also require `"types": ["bun"]` in `compilerOptions`. Keep any other type packages your project already lists. See [Bun's TypeScript configuration](https://bun.com/docs/typescript-6).

## Process images with `Bun.Image`

[`Bun.Image`](https://bun.com/docs/runtime/image) provides a Sharp-shaped, native image pipeline without an external package or native add-on build. On the Automate.ax Linux runtime, it can decode, resize, rotate, and encode JPEG, PNG, and WebP images.

Use it inside an action handler so the I/O and processing happen during execution:

```ts theme={null}
import {
  automation,
  defineAction,
  markSignificant,
  onDashboardRun,
} from "automate.ax"
import { z } from "zod"

const resizeImage = defineAction("Resize image")
  .input(z.object({ url: z.url() }))
  .output(
    z.custom<Uint8Array<ArrayBufferLike>>(
      (value) => value instanceof Uint8Array,
    ),
  )
  .retry({ replaySafety: "safe" })
  .handler(async ({ input }) => {
    const response = await fetch(input.url)

    if (!response.ok) {
      throw new Error(`Image download failed with ${response.status}`)
    }

    return new Bun.Image(await response.arrayBuffer(), {
      maxPixels: 40_000_000,
    })
      .resize(1024, 1024, { fit: "inside", withoutEnlargement: true })
      .webp({ quality: 82 })
      .bytes()
  })

export default automation("Resize an image", () => {
  const run = onDashboardRun({
    title: "Resize image",
    fields: [{ name: "url", type: "url", label: "Image URL" }],
  })
  const resized = resizeImage({ url: run.data.url })

  markSignificant(resized)
})
```

An organization member supplies the image URL and starts the action from the dashboard. The WebP bytes appear in the action output, and `markSignificant` keeps the successful run in the default Recent runs view.

Feed `Bun.Image` validated bytes rather than a request-supplied filesystem path, and set `maxPixels` before decoding to reject decompression bombs.

## Finish work inside the action handler

An action must finish its work before its handler returns. Don't start a long-lived server, background process, or `Bun.cron` job and expect it to continue afterward. Use Automate.ax triggers such as [`onSchedule`](/reference/triggers/on-schedule) for durable scheduling.

The runtime can't modify the deployed project files. Use `/tmp` for temporary files, or keep data in memory. Custom code doesn't receive Automate.ax database credentials or the Lambda execution role's AWS credentials. Use integration accounts or credentials you explicitly provide for external services.
