Search Docs
Loading...
Skip to content

Host the Executor

Run the executor in production, hardened, with a new container for each conversation and outbound traffic limited to the hosts it needs. Exports are charged to your IMG.LY account.

This guide takes the executor from the local container a quickstart kit starts with npm run executor to production. The TypeScript on this page is type-checked against the CoDesign SDK; the shell commands and Kubernetes manifests are not run. For what is supported, see Status.

What the Executor Is#

The executor is an HTTP server that IMG.LY publishes as the Docker image imgly/codesign-executor:1.86.0. It holds CE.SDK, IMG.LY’s design engine, and runs the short JavaScript programs the AI model writes to change a design. It also charges every file it exports to your IMG.LY account (Billing). Your agent runner is your own code: it calls the model in a loop, keeps designs in your storage, and calls the executor over HTTP. Both terms, and the rest of the SDK’s, are in Terminology.

You run the image unchanged. You do not build it, add nothing to it, and write no executor of your own. What varies per product or tenant, such as brand fonts, colors, and where your images live, reaches the executor from your runner with each engine session as CE.SDK plugin modules (JavaScript files that add fonts, images, and colors to an engine): the same plugins your browser editor applies ( Bring Your Brand). Your designs never live on the executor: your runner reads and writes them in your own store ( Connect Your Storage), and the engine holds a copy of the one it works on.

Two words this page uses. A conversation is one piece of work your product gives the agent: one chat, one batch job, one API request. Your runner names it with an id of its own, prepareCoDesign({ conversation }). An engine session is the engine working on one design of that conversation. The first tool call on a design opens it, and later calls on that design reuse it.

The settings below keep each conversation apart from every other one, from your network, and from your cloud’s credentials. For what the model’s code can reach, and where each key lives, see Security.

From the Quickstart to Production#

The quickstart runs one executor on your machine for development, with npm run executor: a plain docker run with --restart always. The container keeps its record of which conversation it serves (its binding, explained below) in memory, so it comes back unbound after each run. It has none of the hardened settings, no control of its outbound traffic, and a token anyone can read in the kit. Its acquire function, the function in your runner that names a conversation’s executor, always returns the one address. For production, change these things, in this order:

  1. Run the image with the hardened settings and a token of your own (Run the Image Hardened).
  2. Run one executor for each conversation that is open at the same time (Run Enough Executors).
  3. Give each conversation a new container, and drop the restart policy (A New Container for Each Conversation).
  4. Replace the quickstart’s acquire with one that gives each conversation its own executor, and call codesign.release() when the conversation is done (Find a Conversation’s Executor).
  5. Let only your runner reach the executor’s port, and block all outbound traffic except the hosts the executor needs (Allow Only the Hosts the Executor Needs).
  6. Pin the SDK and the image to the same version, and upgrade both together ( Versions and Upgrades).

On Kubernetes, every step has its own form, in Run It on Kubernetes.

Run the Image Hardened#

Pull the image tagged with the same version as the SDK your runner installs, then run one container per conversation, removed when it exits:

Terminal window
docker pull imgly/codesign-executor:1.86.0
export IMGLY_CESDK_LICENSE=<your CoDesign license key>
export EXECUTOR_TOKEN=$(openssl rand -hex 32) # a secret the container and the runner share
docker run -d --rm -p 127.0.0.1:8080:8080 \
--read-only --tmpfs /tmp:rw,noexec,nosuid,size=512m \
--cap-drop ALL --security-opt no-new-privileges \
--pids-limit 256 --memory 2g --cpus 1 \
-e IMGLY_CESDK_LICENSE -e EXECUTOR_TOKEN \
imgly/codesign-executor:1.86.0
curl http://localhost:8080/health

/health answers with a JSON status once the executor is up (its fields are in A New Container for Each Conversation). A container that cannot start exits and logs the reason, and --rm removes it, log included: for a first try, leave out -d --rm and read the log in your terminal. 127.0.0.1 keeps the port on your own machine; in production, only your runner may reach it.

Setting Why
--rm Docker removes the container when it exits after its conversation. Start a new one for the next.
--read-only The model’s code cannot change the image’s files, and nothing it writes outlives the container.
--tmpfs /tmp:…,size=512m Scratch space in memory, gone with the container. Optional, unless your designs embed large media (below).
--cap-drop ALL Removes the Linux privileges a container gets by default. The executor needs none of them.
--security-opt no-new-privileges No program in the container can gain privileges, even one marked setuid.
--pids-limit 256 Stops code that starts processes until the machine runs out.
--memory 2g, --cpus 1 A conversation that fills memory or loops ends only its own executor, and cannot starve other ones.

Size /tmp for embedded media. Without large embedded media, the executor runs with no writable /tmp at all, video included. A design that embeds its media, such as a clip a person uploaded that is kept inside the design rather than linked by an https URL, is written through /tmp after every load and edit, so give it /tmp of at least twice the largest design’s embedded media: 512 MB covers designs with up to about 200 MB embedded; for videos with uploaded clips, use more, such as 2 GB. Media linked by URL takes no room there. A /tmp in memory counts against the container’s memory: what it holds is taken from --memory, so raise --memory by the size you give /tmp (with a 2 GB /tmp, 4 GB in all). A design with more than 256 MB embedded gets one encode attempt, not three (Limits the Executor Sets). A design too large for /tmp fails with checkpoint_failed, and the message says that /tmp was too small.

  • IMGLY_CESDK_LICENSE (or CESDK_LICENSE) is your CoDesign license key itself. Contact sales to get a CoDesign license key. A value of 128 characters or more, which is a license file or a grant (a short-lived license IMG.LY issues for one engine) rather than a key, is refused at start. The executor activates the key with api.img.ly when it starts. A container that cannot reach api.img.ly within 10 seconds, or whose key is not accepted, exits and logs the reason, for example could not reach the license server https://api.img.ly/activate: ….
  • EXECUTOR_TOKEN is a secret you make yourself, one for all your executors and runners. Your runner sends it as a bearer token, and the executor answers 401 to a different one, which your runner sees as the error kind executor_unauthorized. The image refuses to start without it. GET /health needs no token, so your platform’s health check can call it.
  • Do not add --init, and do not wrap the image’s command in a shell or in tini. The server that holds your license key must be the first process of its own process namespace and run without a debugger, or it refuses to start and logs why. The reason is in Why Your License Key Is Safe in the Container. Platforms that start every container with an init of their own, such as Modal, Fly.io, or ECS with initProcessEnabled, work where they let a process create a user namespace without privileges: the image then gives the server a process namespace of its own (Run It on Modal). Where they do not, as under Docker’s default seccomp profile with --init, it refuses to start. It also refuses to start with --inspect in NODE_OPTIONS, or with any of the session settings EXECUTOR_ONE_SESSION, EXECUTOR_MAX_SESSIONS, EXECUTOR_IDLE_MS, and EXECUTOR_MAX_LIFETIME_MS set, because the image fixes them.
  • PORT is the port it listens on, 8080 by default.
  • Run the image built for the host’s CPU (x64 or arm64; IMG.LY publishes both for the image without video). An x64 image emulated on an arm64 machine, such as Apple silicon, works but renders far slower: use it only to try video on such a machine (Run It With Video).

To be sure every executor runs the same build, you can pin the image by its digest instead of its tag (imgly/codesign-executor@sha256:…), or record the digest each deploy pulled. This command prints it:

Terminal window
docker buildx imagetools inspect imgly/codesign-executor:1.86.0

Limits the Executor Sets#

The executor sets its own limits. These cannot be changed:

  • A design’s engine session ends after 3 minutes without a call.
  • The engine closes 30 seconds after its last engine session ended, or 30 minutes after it started however busy (the call in flight finishes first). Then the executor exits.
  • A single call ends after 5 minutes without progress. The executor answers it with HTTP 422, an error the model reads (your own calls reject with the kind executor_failed), and then exits, so the runner does not send the same runaway code again; the next call loads the design on a new executor.
  • A container that gets no engine session within 10 minutes exits.

With video on, each encode also has a time budget. One that runs out is tried again on a fresh engine with the design reloaded, up to three attempts in all; a design with more than 256 MB of embedded media gets only one ( Plan for Export Time). You can change the budget and the number of attempts with the EXECUTOR_ENCODE_* variables ( The Executor Image’s Environment Variables).

Still set a deadline per container from outside, as a backstop. Make it longer than the executor’s own limits. Without video, that is at least 45 minutes: the 10 minutes a container may wait for its first session, the 30-minute engine limit, and the 5 minutes a call in flight may still take. With video, it is at least 75 minutes, because the call in flight can be a video export of up to about 21 minutes, plus up to 10 minutes for its upload to your uploadExportURL. A container stopped during that upload has charged the export and not stored it. On Kubernetes, that is the activeDeadlineSeconds of the executor’s Job. A conversation still working when that deadline stops its container moves to a new one on its next call and loads its design there from your store.

Run Enough Executors#

An executor serves one conversation. It runs one engine, and every design of that conversation opens on it in turn, one call at a time, so a conversation never needs more than one engine’s memory however many designs it opens. So the number of executors you run is the number of conversations that can be open at the same time. To estimate it, count your peak of active chats or jobs: each holds its executor until 3 minutes and 30 seconds after its last call, or until you release it.

Give each executor one vCPU and 2 GB of memory. Renders are CPU-bound, so less than one vCPU makes every preview and export slower. The engine’s memory grows with the designs a conversation opens, and the executor sets no limit of its own, so the --memory you give the container is what stops it. A conversation whose executor stops moves to a new one on its next call. Try your largest designs before you size a production deployment. Each exported file passes through your runner’s memory on its way to your uploadExport function, so size the runner for the largest export you allow.

When acquire has no executor to give, it returns undefined, and the call fails with a CoDesignError of kind executor_unreachable. Your product can retry it for a while, or queue the turn. If you see that error often, run more executors, and call codesign.release() for a conversation’s designs when the conversation is done, so their engine sessions end at once instead of after 3 idle minutes. Once the last engine session of the conversation has ended, the executor exits 30 seconds later. So never release after every turn: the next turn would wait for a new executor.

While an executor is exiting it answers 503. A call that opens a design and finds it so waits up to 60 seconds for it to come back, then fails with kind executor_capacity; any other call fails at once.

Run It With Video#

To let the agent export video and audio ( Export Video), run the video image, imgly/codesign-executor:1.86.0-video, and give it 2 vCPUs. IMG.LY publishes two images of the same executor:

Image Exports CPUs Codecs
imgly/codesign-executor:1.86.0 Images, PDFs, and design files; no video or audio x64 and arm64 None
imgly/codesign-executor:1.86.0-video All of these, plus video and audio (MP4, WebM, M4A, WAV) x64 Open-source H.264, AAC, VP9, and Opus encoders, and FFmpeg to decode clips (Codecs in the Video Image)

The video image renders on an NVIDIA GPU when the container has one, and on the CPU otherwise (Video on an NVIDIA GPU). It is larger: about 530 MB compressed and 2 GB on disk, against 250 MB and 930 MB. The video image always exports video; the image without video never does.

To try video on an arm64 machine, such as a Mac with Apple silicon, run the x64 video image under emulation: add --platform linux/amd64 to docker run. It renders far slower, so judge export times on an x64 host.

Video needs no other SDK or CE.SDK version than the rest of your deployment ( Versions and Upgrades). The same hardened settings apply, with more CPU:

Terminal window
docker run -d --rm -p 127.0.0.1:8080:8080 \
--read-only --tmpfs /tmp:rw,noexec,nosuid,size=512m \
--cap-drop ALL --security-opt no-new-privileges \
--pids-limit 256 --memory 2g --cpus 2 \
-e IMGLY_CESDK_LICENSE -e EXECUTOR_TOKEN \
imgly/codesign-executor:1.86.0-video

The /tmp in this command is optional, as on the image without video, unless your designs embed large media (Size /tmp for embedded media). With it, the image keeps the video plugins it found at the first engine start there, so later engine starts in the container are faster. At start, the executor encodes a tiny video to check that video works. If it does not, it starts without video and logs why, in a line that starts with engine: video:; every video export is then refused with video_unsupported. To check from your runner, see Switch Video On.

Variable Default What it does
EXECUTOR_DEVICE not set Where the video image renders. Not set: on the GPU when the container sees an NVIDIA GPU and its graphics (EGL) driver, else on the CPU, and the log says which and why. gpu or cpu chooses. auto lets the engine pick, which is slower; do not use it. Any other value stops the container at start.

Codecs in the Video Image#

The video image encodes MP4 and M4A with open-source H.264 and AAC encoders, and WebM with VP9 and Opus. The engine logs the H.264 and AAC encoders, at the first export, as “intended for TESTING and DEVELOPMENT purposes only”: IMG.LY provides no support and no guarantee of legal compliance for them, and you use them in production at your own risk ( Codecs). The image also contains FFmpeg’s libraries in their GPL build, with x264 and x265, which the executor uses to decode the clips in a design. Check the licenses and patent terms that apply to you before you ship it in production. The image without video contains no codecs at all.

Size Video Executors#

One export uses about two cores: one renders the frames, one encodes them. So give each video executor 2 vCPUs; with one, an export takes about one and a half times as long, and a third does nothing for one export. A conversation that makes only still designs on a video executor uses the second vCPU for nothing, so you can run two pools of executors, one of each image, and pick in acquire by what the conversation is for. Keep a conversation in its pool: when its executor is lost, a replacement from the other pool answers with other abilities, and the session ends with executor_changed.

Give it 2 GB of memory. A design of text, shapes, and images stays under 500 MB while it exports. Each 1080p video clip in a design adds 350 to 480 MB, so 2 GB holds a design with up to three clips. For longer or larger footage, give more memory, or tell the model in your system prompt how many clips a design may hold. A container that runs out of memory stops, and the next call loads the design on a new executor.

For export times and the time budget of each encode, see Plan for Export Time. Video executors on one host share its memory bandwidth. Beyond about one export for every two physical cores, more executors on the host make each export slower without exporting more videos per minute.

Video on an NVIDIA GPU#

On a GPU, the video image renders the frames there and still encodes on the CPU. It exports 1.5 to 2.5 times faster than on the CPU alone: about 1.5 times for a short video of text and shapes, and up to 2.5 times for a long one with effects over footage, such as a blur over a full-frame clip. It pays off most for those videos and for 4K. Give the container the GPU with --gpus all:

Terminal window
docker run -d --rm -p 127.0.0.1:8080:8080 --gpus all \
--read-only --tmpfs /tmp:rw,noexec,nosuid,size=512m \
--cap-drop ALL --security-opt no-new-privileges \
--pids-limit 256 --memory 2g --cpus 2 \
-e IMGLY_CESDK_LICENSE -e EXECUTOR_TOKEN \
imgly/codesign-executor:1.86.0-video
  • The host needs the NVIDIA Container Toolkit and the full NVIDIA driver with its graphics (GL and EGL) libraries, not the headless or compute-only driver that many cloud GPU images have. The image holds nothing of NVIDIA’s: the toolkit mounts the driver’s libraries from the host. On Ubuntu, the graphics libraries are the package libnvidia-gl-<version> of the installed driver.

  • Regenerate the toolkit’s CDI spec after you install it, on a host whose toolkit uses one (/var/run/cdi/nvidia.yaml). The spec lists the driver files a container gets, and one made before libnvidia-gl leaves out EGL, so the image renders on the CPU. Run one of:

    Terminal window
    sudo systemctl start nvidia-cdi-refresh.service
    sudo nvidia-ctk cdi generate --output=/var/run/cdi/nvidia.yaml
  • --gpus all gives the container the GPU. Where the NVIDIA runtime is not Docker’s default, add --runtime=nvidia. The image sets NVIDIA_DRIVER_CAPABILITIES to what it needs; leave it unset.

  • The log says where it renders, and why. nvidia-smi working in the container is no proof of the GPU being used: it needs only the compute part. On a host without the graphics libraries, the image renders on the CPU:

    billed executor: renders on the gpu: an NVIDIA GPU and its EGL driver are visible (EXECUTOR_DEVICE is not set)
    billed executor: renders on the cpu: an NVIDIA GPU is visible, but not its EGL driver (the host needs the driver's graphics libraries, libnvidia-gl) (EXECUTOR_DEVICE is not set)
    billed executor: renders on the cpu: no NVIDIA GPU is visible (EXECUTOR_DEVICE is not set)
  • It runs with the same hardened settings, with no capability, group, or writable folder beyond /tmp.

  • One GPU serves many executors. Each takes about 100 MB of GPU memory, so the host’s vCPUs, two per executor, decide how many fit, not the GPU.

  • The first engine start finds the GPU, which takes about 1.4 seconds; later starts in the same container take about 0.6 seconds, when /tmp is writable.

On Kubernetes, request the GPU through your cluster’s NVIDIA device plugin (nvidia.com/gpu: 1 in limits), with the same libraries on the node.

A New Container for Each Conversation#

The image binds to the first conversation that opens a design on it and refuses every other with HTTP 409, which your runner sees as the error kind executor_bound. GET /health says whether it is bound, without a token:

{ "result": { "sessions": 0, "accepting": true, "bound": false } }

The answer has more fields than these three. When the conversation’s engine has closed, the executor exits.

Start a new container from the image for the next conversation, and never hand a used one to another customer. The reason is that cleaning up after model-written code misses things. Only a new container, with the image’s own files and a new process, is clean.

What your platform does when an executor exits decides what the next one gets:

When an executor exits, your platform… The next executor gets
starts a new container from the image the image’s files and a new process, bound to nobody: clean
restarts the same container (Docker’s --restart always) a new process, but every volume, including the one the image keeps its binding in, so it still serves only the conversation it served before. Without --read-only, also the files the last conversation wrote
restarts the container in the same Kubernetes pod the image’s files, but the pod’s volumes, its /dev/shm, and its shared memory, even with a read-only root. With the binding in memory it comes back unbound, so it is not clean but looks clean to the next conversation

So your platform must:

  • start each container with the settings above, with --rm and no restart policy, and with an address of its own that only your runner can reach, such as its own host port (-p 8081:8080) or its own pod
  • hand a container to a new conversation only after GET /health answers with result.bound false and result.accepting true
  • start a replacement when a container exits, so enough are ready. A pool of containers started ahead is fine, as long as each one serves one conversation and never returns to the pool.
  • after you deploy a new build, replace every container still running the old image. A conversation whose executor is lost and comes back on another CE.SDK version, other abilities, or other asset sources ends: the call rejects with executor_changed, and calling again opens a new session on the new executor ( Versions and Upgrades).

The image keeps its binding in /var/lib/codesign-executor, a volume it declares, which is why a restarted container stays bound. Where that folder cannot be written (a read-only root with no volume there, as in a Kubernetes pod), the executor keeps the binding in memory and says so in its log. That is enough when the container is never restarted in place.

A restart policy therefore only suits trying the image out, where every conversation is yours, as in the quickstart, which also keeps the binding in memory (a tmpfs on /var/lib/codesign-executor) so that each restart is unbound. Docker refuses --rm and --restart together.

Nothing reports a reused container that the binding does not catch: it looks healthy either way. To check your platform, have one conversation’s code write a file under /tmp and the next conversation look for it, and send a second conversation to the first one’s executor: it must be refused with executor_bound.

Find a Conversation’s Executor#

In your runner, remoteExecutors tells the SDK where your executors are. You give it an acquire function. The SDK calls it with { conversation, signal } before it opens an engine session for a design of the conversation, when it ends one (codesign.release() must reach the executor that holds it), and again when the executor was lost. acquire returns:

  • { url }: the executor’s address. The SDK sends its requests to url plus a path.
  • { url, fetch }: also how to reach that executor, when a plain HTTP request to url cannot, such as a platform that reaches each container through its own API. fetch takes and answers what the global fetch does.
  • undefined: no executor can be had now. The call fails with executor_unreachable.

acquire must keep two rules:

  1. The same conversation gets the same executor while that executor lives, so a call finds its design already loaded and the binding does not refuse it.
  2. A new conversation gets an executor no other conversation used. If you hand out one that served someone else, it refuses with executor_bound. That is the safety net, not the plan.

If the conversation’s executor has exited, for example when the user comes back after its idle minutes, give the conversation a new, unused executor, as for a new conversation. The design loads there from your store. Never hand it a container that served someone else, and never wait for the old one to come back.

acquire runs on every engine session, so for a conversation that has an executor it must be fast: a lookup in a map or one row of a table. Starting a container for a new conversation may take seconds; a pool of containers started ahead avoids that wait. When an executor is lost (it exited, crashed, or cannot be reached), the SDK calls acquire again for the same conversation and loads the design on the executor it answers from your store. Every change was saved there after the call that made it, so nothing is lost but the time of one load.

This pool hands out executors your platform started ahead, at fixed addresses. It remembers which conversation holds which, and gives a new conversation one that nobody holds and whose /health reports bound: false. Your platform replaces each container that exits with a new one at the same address, so the list never changes. Fixed addresses suit Docker Compose or virtual machines; on Kubernetes a new pod gets a new address (Run It on Kubernetes):

import type { AcquiredExecutor } from '@imgly/codesign-sdk';
/**
* A pool over executors your platform started ahead, at `urls`. Each
* conversation gets its own and keeps it; `release` gives a finished
* conversation's back, so its entry does not stay forever.
*/
export function executorPool(urls: readonly string[]): {
acquire: (req: {
conversation: string;
signal?: AbortSignal;
}) => Promise<AcquiredExecutor | undefined>;
release: (conversation: string) => void;
} {
// conversation → the url of its executor.
const held = new Map<string, string>();
// Whether an executor is up, bound to no conversation, and taking sessions.
const unbound = async (url: string, signal?: AbortSignal) => {
try {
const response = await fetch(`${url}/health`, {
...(signal !== undefined ? { signal } : {})
});
const body = (await response.json()) as {
result?: { bound?: boolean; accepting?: boolean };
};
return body.result?.bound === false && body.result.accepting === true;
} catch {
return false; // unreachable or starting: not one to hand out now
}
};
// One claim at a time, so two conversations never pick the same executor
// while the first one's health check is still in flight.
let queue: Promise<unknown> = Promise.resolve();
const claim = async (conversation: string, signal?: AbortSignal) => {
const mine = held.get(conversation);
// Rule 1: the same conversation, the same executor. If it was lost and
// your platform replaced it at the same address, the new one binds to
// this conversation on its first session.
if (mine !== undefined) return mine;
// Rule 2: a new conversation gets an executor nobody holds and that
// reports `bound: false`. A container that served another conversation
// reports `bound: true` until your platform replaces it.
const taken = new Set(held.values());
for (const url of urls) {
if (taken.has(url) || !(await unbound(url, signal))) continue;
held.set(conversation, url);
return url;
}
return undefined; // all taken: the call fails as executor_unreachable
};
return {
acquire: async ({ conversation, signal }) => {
const picked = queue.then(() => claim(conversation, signal));
queue = picked.catch(() => undefined);
const url = await picked;
return url === undefined ? undefined : { url };
},
release: (conversation) => {
held.delete(conversation);
}
};
}

Use it where your runner prepares the tools. When the job is done, codesign.release() ends the design’s engine session, and pool.release() removes the job from the pool’s record, so its address can go to a new conversation once the replacement container reports bound: false:

import {
googleFonts,
prepareCoDesign,
remoteExecutors,
type CoDesign
} from '@imgly/codesign-sdk';
import { executorPool } from './executor-pool.js';
// Yours: your agent loop over codesign.tools, given the brief.
async function runYourAgent(
_codesign: CoDesign,
_brief: string
): Promise<void> {
throw new Error('yours to write');
}
// The addresses of the executors your platform keeps started.
const pool = executorPool(['http://executor-1:8080', 'http://executor-2:8080']);
export async function runJob(jobId: string, brief: string): Promise<void> {
const codesign = prepareCoDesign({
// One job, one executor: no other job's code ever runs where this one's did.
conversation: jobId,
executors: remoteExecutors({
acquire: pool.acquire,
// Sent as `Authorization: Bearer …`; must equal the executors' EXECUTOR_TOKEN.
token: process.env.EXECUTOR_TOKEN
}),
plugins: [googleFonts()],
gateway: false
});
try {
await runYourAgent(codesign, brief);
} finally {
// Ends the current design's engine session now (pass { design } for each other one the job opened);
// the executor exits 30 seconds after the last one ends, and your platform replaces it.
await codesign.release();
pool.release(jobId);
}
}
  • The example passes only the options it needs. plugins lists the CE.SDK plugins every engine session applies; googleFonts() is IMG.LY’s Google Fonts catalog. gateway: false leaves out image generation. Without a designs store, designs live in the runner’s memory; without uploadExport, the model cannot export, and only your own codesign.export() calls export files. Both are optional ( API Reference).
  • The pool keeps its record in the runner’s memory, so it fits one runner process. With several runner processes, keep it in a table every runner shares, so two never claim the same executor: one row per executor (url, conversation), and a claim that sets conversation only where it is still empty, which only one runner can win. Clear a row when its executor is replaced.
  • Conversation ids from several tenants. acquire gets the conversation id and nothing else. If two of your tenants could ever use the same id, put the tenant in front: conversation: `${tenantId}.${chatId}`.
  • Never put a round-robin load balancer in front of executors, and do not rely on cookie-based “sticky sessions”, which some platforms move while scaling. Each executor needs an address of its own, or your platform must route by conversation.
  • A platform in front of the executors. The executor always answers in JSON. If a proxy or your container platform can answer instead, for example when it cannot start a container, turn any answer of 500 or more that is not JSON (and a 429 of its own) into a 502. The SDK counts a 502 or 504 as an executor it cannot reach: the call rejects with executor_unreachable, and you can retry it. Any other answer that is not JSON fails the call with the text it got.
  • Names your platform shows. Where your platform names a container after the conversation, use a hash of the conversation id, so no chat id appears in its dashboard.

Allow Only the Hosts the Executor Needs#

Deny all outbound traffic from the executor except to these hosts:

Host What the executor fetches from it
your sources’ origins each origin your plugin modules call: to search a tenant’s images and fonts, fetch them, and store uploads. For example https://api.acme.com, and no other part of your API
your asset host the images and fonts of the tenant it serves
your font host brand font files, if they are not on your asset host
cdn.img.ly CE.SDK’s own assets, the Google Fonts catalog and its font files, CE.SDK’s catalogs when you list cesdkDefaults() or cesdkDemo(), and the emoji font
api.img.ly license activation when the container starts, and the charge for each export
your upload host with uploadExportURL: the host of the upload URLs it answers, where the executor stores each export. For example your bucket’s https://acme-exports.s3.eu-central-1.amazonaws.com

The executor never calls your runner or another executor, so block those too, and block your cloud’s metadata address (169.254.169.254).

The model’s code can open any connection the network allows, so the list keeps your designs and your cloud’s credentials inside ( Security). The image cannot restrict its own traffic, so enforce the list outside the container, with a firewall or an egress proxy.

With an egress proxy, set HTTPS_PROXY (and HTTP_PROXY, NO_PROXY as you need) and NODE_USE_ENV_PROXY=1 on the container. Without NODE_USE_ENV_PROXY, Node.js ignores the proxy variables, the license activation goes direct and fails behind the allow-list, and the container exits at start. A proxy that re-signs HTTPS needs the certificate of its certificate authority (CA), by path, in NODE_EXTRA_CA_CERTS ( the image’s environment variables).

A missing cdn.img.ly fails when an engine session opens: the call rejects with plugin 0 (ly.img.google-fonts): initialize threw: Google Fonts: could not load …. You can serve a copy of the catalog from a host of your own with googleFonts({ baseURL }); the font files it lists still load from cdn.img.ly. A session given an image or font address it cannot reach names it in every edit, preview, and export. Run a render and an import through your allow-list before you rely on it.

Inbound, let only your runner reach the executor’s port, with a firewall rule or your platform’s network policy. Whoever holds the executor token and reaches the port can open engine sessions there, so the network rule keeps a leaked token from being enough on its own.

Run It on Kubernetes#

The SDK ships no Kubernetes controller. Starting, finding, and removing executors is code you write in acquire, against your cluster’s API. The shape that keeps every rule above is one Job per conversation:

  1. For a new conversation, or one whose executor has exited, acquire creates a Job from the manifest below and records which conversation it serves (in a table every runner shares, if you run several runners).
  2. It waits until the pod has an IP and GET http://<pod IP>:8080/health answers accepting: true and bound: false.
  3. It returns { url: 'http://<pod IP>:8080' }. Your runner runs inside the cluster, so it can reach the pod’s IP.
  4. For a conversation whose pod still runs, it returns the same url from its record, with no call to the cluster.
  5. When the executor exits, its Job finishes, and ttlSecondsAfterFinished makes Kubernetes delete the Job and its pod. Clear the conversation’s record then, or when its next call finds the pod gone.

A Job with backoffLimit: 0 and restartPolicy: Never runs its container once. A Deployment, StatefulSet, or DaemonSet cannot: they allow only restartPolicy: Always, which restarts a used container in its pod. To save the seconds a new pod takes to start, keep a few Jobs started ahead, and let acquire claim one by giving it the conversation’s label; a claimed pod never goes back. A pod nobody claims exits after 10 minutes, so start new ones as they finish.

apiVersion: batch/v1
kind: Job
metadata:
generateName: codesign-executor- # or a hash of the conversation id, never the id itself
labels: { app: codesign-executor }
spec:
backoffLimit: 0 # an executor that exited is never started again
activeDeadlineSeconds: 2700 # the 45-minute backstop
ttlSecondsAfterFinished: 60 # deletes the Job and its pod once the executor exits
template:
metadata:
labels: { app: codesign-executor }
spec:
restartPolicy: Never
automountServiceAccountToken: false # the pod holds no cluster credentials
containers:
- name: executor
image: imgly/codesign-executor:1.86.0
ports: [{ containerPort: 8080 }]
envFrom: [{ secretRef: { name: executor } }] # IMGLY_CESDK_LICENSE, EXECUTOR_TOKEN
env:
- { name: HTTPS_PROXY, value: 'http://egress-proxy:3128' } # your egress proxy
- { name: NODE_USE_ENV_PROXY, value: '1' }
readinessProbe:
httpGet: { path: /health, port: 8080 }
periodSeconds: 1
resources:
requests: { cpu: '1', memory: 2Gi }
limits: { cpu: '1', memory: 2Gi }
securityContext:
runAsNonRoot: true
runAsUser: 1000
runAsGroup: 1000
readOnlyRootFilesystem: true
allowPrivilegeEscalation: false
capabilities: { drop: [ALL] }
seccompProfile: { type: RuntimeDefault }
  • Readiness. The probe tells Kubernetes the server is up. It checks the status code only, not bound, so acquire reads /health itself before it hands the pod out.
  • User. The image runs as UID and GID 1000, so runAsNonRoot can check it. Keep runAsUser: 1000: the image’s list of video plugins is that user’s, so under another UID the engine rescans every plugin at each start, which slows every new conversation.
  • Requests and limits are equal: one vCPU and 2 GiB (Run Enough Executors). With video, use the image imgly/codesign-executor:1.86.0-video, set cpu: '2', and set activeDeadlineSeconds: 4500, the 75-minute backstop for video (Run It With Video, Limits the Executor Sets).
  • Leave shareProcessNamespace off. It makes another process the pod’s first, and the image refuses to start under it. The pod needs a /tmp volume only for designs that embed large media: then mount an emptyDir with medium: Memory there, with a sizeLimit of twice the largest design’s embedded media, and add that size to the memory limit, since a memory volume counts against it.
  • Processes. Kubernetes limits processes per pod only for a whole node, with the kubelet’s podPidsLimit: a setting your platform team owns, not part of the pod.

Give the executors’ pods a NetworkPolicy that lets in only your runner, and lets out only your egress proxy and DNS:

apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: codesign-executor
spec:
podSelector: { matchLabels: { app: codesign-executor } }
policyTypes: [Ingress, Egress]
ingress:
- from: [{ podSelector: { matchLabels: { app: your-runner } } }]
ports: [{ port: 8080 }]
egress:
- to: [{ podSelector: { matchLabels: { app: egress-proxy } } }]
ports: [{ port: 3128 }]
- to: [{ namespaceSelector: {}, podSelector: { matchLabels: { k8s-app: kube-dns } } }]
ports: [{ port: 53, protocol: UDP }, { port: 53, protocol: TCP }]

A NetworkPolicy matches addresses, not host names, so it cannot allow cdn.img.ly and api.img.ly by name. Either send the executor’s traffic through an egress proxy that allows only the hosts above, as these manifests do (the image passes HTTPS_PROXY and NODE_USE_ENV_PROXY to the engine too), or use a network plugin (CNI) whose policies allow domain names.

Run It on Modal#

Both images run on Modal unchanged, one Modal Sandbox per conversation. Modal starts every container as root, with its own init as the first process. The image handles both: it drops to its own user, UID 1000, and starts the server as the first process of a process namespace of its own, and logs that it did. The model’s code runs inside that namespace, as everywhere else.

Your runner’s acquire creates the sandbox with Modal’s JavaScript SDK (npm install modal), waits until the executor answers on /health, and returns the sandbox’s address; release ends it:

import type { AcquiredExecutor } from '@imgly/codesign-sdk';
import { ModalClient, type Sandbox } from 'modal';
/**
* One Modal Sandbox per conversation, from IMG.LY's image, unchanged. Modal
* reads its own credentials from MODAL_TOKEN_ID and MODAL_TOKEN_SECRET.
*/
export function modalExecutors(opts: {
app: string; // your Modal app, such as 'codesign-executors'
secret: string; // a Modal Secret with IMGLY_CESDK_LICENSE and EXECUTOR_TOKEN
gpu?: string; // such as 'L4' or 'A10G'; without it, the CPU renders
}): {
acquire: (req: {
conversation: string;
signal?: AbortSignal;
}) => Promise<AcquiredExecutor | undefined>;
release: (conversation: string) => Promise<void>;
} {
const modal = new ModalClient();
// conversation → its sandbox and the sandbox's address.
const held = new Map<string, { sandbox: Sandbox; url: string }>();
const start = async (signal?: AbortSignal) => {
const app = await modal.apps.fromName(opts.app, { createIfMissing: true });
const image = modal.images
.fromRegistry('imgly/codesign-executor:1.86.0-video')
.dockerfileCommands(['ENTRYPOINT []']);
const sandbox = await modal.sandboxes.create(app, image, {
command: ['/app/start.sh', 'video'], // 'static' for the image without video
encryptedPorts: [8080],
secrets: [await modal.secrets.fromName(opts.secret)],
cpu: 2,
memoryMiB: 2048,
...(opts.gpu !== undefined ? { gpu: opts.gpu } : {}),
timeoutMs: 75 * 60_000 // the backstop for a video executor
});
const url = (await sandbox.tunnels())[8080]?.url;
if (url === undefined || !(await ready(url, signal))) {
await sandbox.terminate();
return undefined; // the call fails as executor_unreachable
}
return { sandbox, url };
};
return {
acquire: async ({ conversation, signal }) => {
const mine = held.get(conversation);
// The same conversation, the same executor, while its sandbox runs.
if (mine !== undefined && (await mine.sandbox.poll()) === null) {
return { url: mine.url };
}
// A new conversation, or one whose executor exited: a new sandbox.
const started = await start(signal);
if (started === undefined) {
held.delete(conversation);
return undefined;
}
held.set(conversation, started);
return { url: started.url };
},
release: async (conversation) => {
const mine = held.get(conversation);
held.delete(conversation);
await mine?.sandbox.terminate();
}
};
}
// Whether the executor at `url` is up and bound to no conversation, within 5 minutes.
async function ready(url: string, signal?: AbortSignal): Promise<boolean> {
const until = Date.now() + 5 * 60_000;
while (Date.now() < until && signal?.aborted !== true) {
try {
const response = await fetch(`${url}/health`, {
...(signal !== undefined ? { signal } : {})
});
const body = (await response.json()) as {
result?: { bound?: boolean; accepting?: boolean };
};
if (body.result?.accepting === true) return body.result.bound === false;
} catch {
// not answering yet
}
await new Promise((resolve) => setTimeout(resolve, 1000));
}
return false;
}

Pass it to remoteExecutors as you would any other acquire, and call its release after codesign.release() when the conversation is done (Find a Conversation’s Executor).

  • One sandbox per conversation. The executor serves the conversation that opened a design on it and exits after it, about 3½ minutes after its last call. Its command then ends, and so does the sandbox: poll() answers its exit code, and the conversation’s next call starts a new one, which loads the design from your store.
  • The image’s own command does not run. The example clears the image’s entrypoint and starts /app/start.sh video, the command the image would run (static for the image without video).
  • Your license key and executor token come from a Modal Secret with the variables IMGLY_CESDK_LICENSE and EXECUTOR_TOKEN, created in Modal’s dashboard or with modal secret create. Your runner holds the same executor token for remoteExecutors.
  • The GPU. With gpu, such as 'L4' or 'A10G', the video image renders on it and logs so; without it, it renders on the CPU.
  • timeoutMs is the container backstop (Limits the Executor Sets): 75 minutes for a video executor. Modal’s default, 5 minutes, would end a conversation in the middle.
  • The address is public. A sandbox’s encrypted port is reachable from the internet; the executor token is what keeps others out ( Security).

Billing#

The executor charges your IMG.LY account for every file it exports, inside the container, before the file leaves it. Your runner holds no billing credential; it only has to let a refused export through to your product.

What Is Charged#

Every export of a file is charged, whoever asked for it: the model, whose export then hands the file to your uploadExport function, or your own codesign.export() call. This covers PDF, PDF/X (the PDF standard for print), InDesign (IDML), PNG, JPEG, WebP, SVG, HTML, Photoshop (PSD), and, with video on, MP4, WebM, M4A, and WAV. For each export, the executor sends Metering (IMG.LY’s billing service) the file’s type, the PDF/X standard it was written to, and one entry for each page, read from the design when it is exported:

  • A PDF has one entry for each of its pages, with the page’s width and height in points. For a page with bleed, that is its trim size, without the bleed.
  • An InDesign file has one entry for each page of the design, like a PDF. It always holds every page.
  • An image has one entry, its width and height in pixels. A PNG of a three-page design is one image.
  • A PSD holds one page, so it has one entry, the page’s width and height in points, like a PDF page.
  • An SVG or HTML file has one entry, with no size.
  • A video (MP4, WebM) has one entry: its length in milliseconds and its frame’s width and height in pixels.
  • A sound file (M4A, WAV, WebM audio) has one entry, its length in milliseconds.

Each export is charged in credits, the same credits your IMG.LY account holds for AI generation. Your balance is in your CoDesign dashboard, where you sign in with your IMG.LY account. For prices, contact sales.

The executor also logs one line for each export it charges, with its file type, its pages, and the render id that charged it once:

metering: charged image/png × 1 (render 3f9c0d…)

An export that Metering had already charged under the same render id logs already charged. An export delivered uncharged during a Metering outage logs delivered unbilled instead, so the log tells the two apart.

Saving the design itself (.imgly, the scene), previews (images of one moment of a video included), edits, and failed renders are free.

A render retried after a lost connection is charged once, and so is the same version of a design exported again in the same format with the same options. An export your runner stopped waiting for before the charge is not charged. Resent within 5 minutes, as a runner does when its connection drops, it is delivered from that render, without encoding it again, and charged once. With uploadExportURL, the charge comes before the upload: a file your store did not accept is charged (export_upload_failed, charged: true unless Metering was unreachable). Exporting it again on the conversation’s same executor is not charged again, and within 5 minutes it is stored from the file already rendered, without rendering it again; on a new executor, after the old one ended, a second charge is possible.

When an Export Is Refused#

The executor refuses an export when:

  • your account has no credits left
  • your license key does not include CoDesign. A plain CE.SDK key starts the engine, but every export is refused. Contact sales to get a CoDesign license key.
  • the export is larger than 16,000 px on its longer side, 500 pages, or 150 MB
  • the export is a PDF the executor cannot count: one that stores its objects compressed, or was updated in place
  • a video or audio export is longer than 60 seconds, or more work than 60 seconds of 1080p at 30 frames per second
  • Metering, IMG.LY’s billing service at api.img.ly, does not accept the charge: for example, a 429 without Retry-After for an account’s export limit, or a render id it does not accept (the message says “update the SDK”)
  • Metering has not answered the container once since it started (see below)

The export then fails with the error kind export_refused and a message, in words for your user, that says which. Retrying unchanged helps only for an export limit, which lifts with time, and for a network failure on the billing route; for the rest, fix the cause first. When the model asked for the export, the tool call rejects with that error and uploadExport is not called; your own codesign.export() calls receive the same error. Show the message, and an upgrade prompt if you sell one. A video or audio export from an executor without video fails differently, with video_unsupported, before anything is charged. Every cause, with what to do about it: Exports Are Refused.

Keep api.img.ly on your allow-list for the container’s whole life:

  • Until Metering has answered the container once, a charge that gets no answer refuses the export, naming the route (https://api.img.ly/exports/claim). So an egress rule that lets the license activation through but blocks /exports/* refuses every export.
  • After that first answer, an outage of Metering (no answer, a 5xx, a 408, or a 429 with Retry-After after the retries) lets the export through uncharged, rather than stopping your product.

Next Steps#

  • Quickstart — run one executor and one design on your machine.
  • Security — see what the model’s code can reach, and where your keys live.
  • Troubleshooting — fix a container that does not start or an export that is refused.
  • API Reference — look up remoteExecutors, release, and the errors.