Skip to content

feat(sandboxes): Add sandboxes to the Ruby SDK - #2

Open
nderjung wants to merge 4 commits into
prod-stagingfrom
nderjung/feat/sandbox-init
Open

nderjung wants to merge 4 commits into
prod-stagingfrom
nderjung/feat/sandbox-init

Conversation

@nderjung

@nderjung nderjung commented Nov 4, 2026

Copy link
Copy Markdown
Member

Adds sandboxes to the Ruby SDK, on top of #1. They wrap the sandbox plugin's generated client, unikraft-cloud-plugin-sandbox-api, the same way the JS SDK does.

ukc.metro(:fra).sandboxes.create do |sb|   # deleted when the block ends
  result = sb.run("ls", "-la", "/")
  puts result.stdout if result.success?

  sb.spawn("cat").write("hi\n").close_write.wait
  sb.files.write("/tmp/a.txt", "hello")
end

The names follow Ruby rather than JS: exec becomes run (Ruby's exec replaces the process), start becomes spawn, stdin is write/close_write, and file methods live under sb.files. As in the rest of the SDK, within: is a server-side wait and timeout: is only the HTTP timeout.

Before this can go green: unikraft-cloud-plugin-sandbox-api has to be on RubyGems first. Until it is, bundle install fails in CI. The end-to-end sandbox tests have not been run against a live account yet.

@nderjung
nderjung force-pushed the nderjung/feat/init branch 11 times, most recently from ea16c49 to 7c9f496 Compare November 25, 2026 02:06
Base automatically changed from nderjung/feat/init to prod-staging November 25, 2026 02:44
@nderjung
nderjung force-pushed the nderjung/feat/sandbox-init branch from f54e713 to 7e37e3a Compare November 25, 2026 02:46
The sandboxes porcelain wraps the generated plumbing of the sandbox
plugin, published as unikraft-cloud-plugin-sandbox-api. Depend on it,
and check that ApiClient still satisfies the transport its Transport
module declares, signature by signature and over the wire.

check_package installs the plugin gems from the bundle's own cache, so
it keeps working without an index and with a locally built plugin gem.

Signed-off-by: Alexander Jung <alex@unikraft.com>
A sandbox is an instance with the sandbox plugin attached, reached at
`ukc.metro(:fra).sandboxes`, or through `Unikraft::Cloud::Sandbox.create`
and `.connect`, which build a client from their options. It lives in one
metro, so it hangs off a metro scope only.

`create` attaches the plugin, applies the image, memory and autokill
defaults, waits for the plugin, and deletes the instance it made when
that wait fails, naming the likely cause. With a block it deletes the
sandbox when the block returns, like `await using` in JS.

Commands run to completion with `run`, which takes a shell line or an
argument vector like Kernel#system, or start with `spawn`, returning a
Command whose standard input reads like an IO (`write`, `close_write`)
and that takes signals as Symbols. Files go through `sb.files`, with
binary Strings sent as bytes and other Strings as UTF-8.

Signed-off-by: Alexander Jung <alex@unikraft.com>
Boot a real sandbox, run commands, and round-trip text and bytes through
its filesystem, then check that the create block deletes the machine:
the platform reports it gone with an error envelope the SDK reads as a
404. Skipped without UKC_TOKEN, like the rest of the live suite.

Signed-off-by: Alexander Jung <alex@unikraft.com>
Show both doors, the create block that deletes the sandbox, commands
with run and spawn, standard input and signals, and the filesystem,
in the README and as a runnable example mirroring the JS one.

Signed-off-by: Alexander Jung <alex@unikraft.com>
@nderjung
nderjung force-pushed the nderjung/feat/sandbox-init branch from 7e37e3a to 36ad067 Compare November 25, 2026 02:47
@nderjung
nderjung requested an adaptive review from Copilot November 25, 2026 03:04

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unresolved sandbox defects can mishandle timeouts, falsely report readiness, leak idle connections after deletion, and ignore explicitly requested deployments.

5 open issues
What changed in this PR

Adds sandbox support to the Ruby SDK, wrapping the generated plugin client with Ruby-style APIs for managing sandbox instances, commands, and files.

Changes:

  • Adds metro-scoped sandbox creation, connection, listing, readiness checks, and block-based cleanup.
  • Introduces command execution, standard input, log access, and file operations.
  • Adds documentation, examples, unit and live tests, plus plugin dependency and packaging support.
File Description
unikraft-cloud.gemspec Declares the sandbox plugin dependency.
test/​unit/​sandboxes_test.rb Tests sandbox lifecycle, commands, and files.
test/​unit/​plugin_transport_test.rb Checks plugin transport compatibility.
test/​support/​fake_cloud.rb Supports binary responses and plugin transport methods.
test/​e2e/​sandbox_test.rb Adds live sandbox integration tests.
README.md Documents sandbox APIs and usage.
Rakefile Installs cached plugin gems during package checks.
lib/​unikraft/​cloud/​resources/​sandboxes/​sandboxes.rb Implements sandbox collection and lifecycle operations.
lib/​unikraft/​cloud/​resources/​sandboxes/​sandbox.rb Adds sandbox handles, readiness, and execution.
lib/​unikraft/​cloud/​resources/​sandboxes/​files.rb Implements sandbox file operations.
lib/​unikraft/​cloud/​resources/​sandboxes/​command.rb Adds command handles, input, logs, and signals.
lib/​unikraft/​cloud/​client.rb Exposes sandboxes on metro scopes.
lib/​unikraft/​cloud.rb Loads sandbox support.
Gemfile.lock Locks the sandbox plugin dependency.
examples/​sandbox.rb Demonstrates sandbox workflows.
CONTRIBUTING.md Explains using locally built plugin gems.

Review effort: Balanced (adaptive)

Comment on lines +133 to +135
ref_kw = kwargs.slice(*Core::Ref.members)
ukc, rest, scope = door(client, kwargs.except(*Core::Ref.members),
"`Sandbox.connect(ref, client:)`")
# 404 or 502, which the loop retries.
Core::Ready.wait_until_ready(**policy, timeout: within, what: "sandbox #{uuid}",
diagnose: ->(_) { diagnose }) do |left|
api.commands.list_commands(headers:, timeout: left)
#
# @param call [Hash] `headers:`, `timeout:`
# @return [Resources::InstanceHandle] carrying what the platform reported
def delete(**call) = instance.delete(**call)
plugin_name = (spec.delete(:plugin_name) || Sandbox::DEFAULT_PLUGIN_NAME).to_s
body = instance_body(spec, plugin_name, spec.delete(:rom))
body[:timeout_s] = boot_within || (ready == false ? 0 : Sandbox::DEFAULT_BOOT_WITHIN)
booting = boot_within&.positive? ? { timeout: boot_within + 10 }.merge(call) : call
body[:timeout_s] = boot_within || (ready == false ? 0 : Sandbox::DEFAULT_BOOT_WITHIN)
booting = boot_within&.positive? ? { timeout: boot_within + 10 }.merge(call) : call
sandbox = attach(create_instance(body, booting), plugin_name)
ready_or_delete(sandbox, ready, headers) unless ready == false
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.

2 participants