Skip to content

Add Container exec and per-start image/instance options with record serialization - #1143

Open
btkostner wants to merge 4 commits into
cloudflare:mainfrom
btkostner:fix/container-env-record
Open

btkostner wants to merge 4 commits into
cloudflare:mainfrom
btkostner:fix/container-env-record

Conversation

@btkostner

@btkostner btkostner commented Nov 13, 2026 •

Copy link
Copy Markdown

Summary

  • Add worker-sys bindings and worker wrappers for running a process in an already-running Container: exec, pid, exit code, buffered stdout/stderr, and kill.
  • Expose per-start image, named/custom instance sizing, snapshot restore handles, and labels for the durable_object scheduling policy. Custom sizing uses the runtime's vcpu, memoryMib, and diskMb property names.
  • Serialize startup/exec options as JavaScript objects, including environment variables and labels as records rather than Maps, while preserving configured values and omitting unset fields.
  • Propagate Reflect::set exceptions from the custom-instance and snapshot builders instead of panicking.

Scope and ordering

This combines the original exec/sizing foundation with its record-serialization correction so the first mergeable contribution does not expose the known broken conversion path. Native Container streaming/loopback capabilities are a separate dependent contribution and must land after this PR.

The exec wrapper here supports buffered output; stream stdin/stdout/stderr, abort signals, and PTY support are not part of this contribution. The existing start/monitor/signal/destroy/TCP-port method signatures remain unchanged. ContainerStartupOptions gains public fields, so exhaustive Rust struct literals need to include them or use new()/Default.

Verification

  • Focused WASM unit tests passed: CARGO_HOME=~/.local/share/cargo with wasm-bindgen-test-runner 0.2.129 and Node.js 26.13.1, ran cargo test --manifest-path ../workers-rs-env-record-upstream/Cargo.toml -p worker --target wasm32-unknown-unknown --lib container::tests; result: 4 passed, 4 filtered, 0.01s.
  • This was a focused test-module run only, not the full test suite; no lint, formatter, smoke run, or deployed native-acceptance check is claimed.

References

btkostner and others added 4 commits October 2, 2026 07:30
worker-sys: extend the Container extern block with exec()/ExecProcess/
ExecOutput, binding Cloudflare's exec() API for running an additional
process inside an already-running container and reading its exit code
and buffered stdout/stderr.

worker: extend ContainerStartupOptions with image/instance/
container_snapshot/labels (the durable_object scheduling policy's
additional ctx.container.start() fields, previously unavailable; the
default policy's image/instance come from Wrangler config instead) and
add idiomatic Container::exec()/ExecProcess/ExecOutput wrappers.

Source: https://developers.cloudflare.com/containers/api/durable-object-container/
and https://developers.cloudflare.com/containers/configuration/scheduling-policy/,
checked 2026-10-02.
…p builders

set_custom_instance and set_container_snapshot built their JS object with
Reflect::set(...).unwrap(). Reflect::set can fail per the ECMAScript spec
(js-sys surfaces that as a Result), and this code runs inside a Worker
request handler, so an avoidable unwrap() is an avoidable panic there.
Both methods now return Result<(), JsValue> and propagate with ?,
matching Container::exec's existing ?-based error propagation in this
same file.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant