withruntime 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 53b4e63218b0587cacbd8e0ad8ec583ba4ce9b32ec0b792208b8f70750b5acd5
4
- data.tar.gz: 3461a8000fc4817de3f06c6f6f40b6e5d29b49312a4e1f9c9dc94a649e91b8ae
3
+ metadata.gz: f471d00ffe082a8a507a514dda86ce4062342e2b5f0e27153309d094a27fb35b
4
+ data.tar.gz: 988ff09e0b418238acb50eba94f81bfa59c579e8103a81bd8b43e551c692f70e
5
5
  SHA512:
6
- metadata.gz: b1bb2aea12c2959b3afcd694ad90124d1c04fcf60201fdece3f5f1264b40bfa3b3f8deec865c5265d806b6e8c389ebacfd4da833648133fdba93b9ece3d7352f
7
- data.tar.gz: d0238775905bea2408a2d930a402f49a4001bf900c3a8c13acbd511aaf5c486b7b01da8b5f93dfc188e50b696e135b8b92dfd75a7f9c74f5d4dcbdfcce63b668
6
+ metadata.gz: e4e8625a16d34f127de6bda5733b2645b733cb7a06ec3af65d87fc48a6b804d17c6d22f03cc657bd3cb64d8c29e3269cc42047aed28b0cf084f25a6cba9a048e
7
+ data.tar.gz: 33311be1f0d80a9ff3fd613acd21a02e0535945271e08af9cdf4b83d1021310479681bb7f07e8acb36663654d130fa29c635dcf796b1489cb9fbeec73d1f9a25
@@ -241,19 +241,20 @@ module WithRuntime
241
241
  # Runs a command and returns its exit code and output. A String runs under
242
242
  # +bash -c+; an Array runs the program directly, with no shell.
243
243
  #
244
- # +cwd+ (default /workspace), +env+ (merged over the sandbox's; put secrets
245
- # here), +stdin+, +timeout+ (seconds, default 60, up to a day; a timeout is
246
- # a result, not an error), +on_stdout+ and +on_stderr+ (stream the command;
247
- # the result keeps everything), and +check+ (raise CommandError on a
248
- # non-zero exit or a timeout).
249
- def exec(command, cwd: nil, env: nil, stdin: nil, timeout: nil, on_stdout: nil, on_stderr: nil,
244
+ # +cwd+ (default /workspace), +user+ ("sandbox", the default, or "root",
245
+ # through the sandbox's passwordless sudo), +env+ (merged over the
246
+ # sandbox's; put secrets here), +stdin+, +timeout+ (seconds, default 60, up
247
+ # to a day; a timeout is a result, not an error), +on_stdout+ and
248
+ # +on_stderr+ (stream the command; the result keeps everything), and
249
+ # +check+ (raise CommandError on a non-zero exit or a timeout).
250
+ def exec(command, cwd: nil, user: nil, env: nil, stdin: nil, timeout: nil, on_stdout: nil, on_stderr: nil,
250
251
  check: false, idempotency_key: nil)
251
252
  streamed = on_stdout || on_stderr || (timeout && timeout > 60)
252
253
  result = if streamed
253
- collect(exec_stream(command, cwd: cwd, env: env, stdin: stdin, timeout: timeout,
254
+ collect(exec_stream(command, cwd: cwd, user: user, env: env, stdin: stdin, timeout: timeout,
254
255
  idempotency_key: idempotency_key), on_stdout, on_stderr)
255
256
  else
256
- body = command_body(command, cwd, env, stdin, timeout)
257
+ body = command_body(command, cwd, env, stdin, timeout, user)
257
258
  CommandResult.new(@t.json("POST", path(":exec"), body: body, key: idempotency_key,
258
259
  timeout: timeout && (timeout + 60)))
259
260
  end
@@ -265,14 +266,14 @@ module WithRuntime
265
266
  # Runs a command and yields its events as they happen: start, stdout,
266
267
  # stderr, exit (each a Hash). Resumes by itself when the server ends a long
267
268
  # stream, so it never drops output. Without a block, an Enumerator.
268
- def exec_stream(command, cwd: nil, env: nil, stdin: nil, timeout: nil, idempotency_key: nil, &block)
269
+ def exec_stream(command, cwd: nil, user: nil, env: nil, stdin: nil, timeout: nil, idempotency_key: nil, &block)
269
270
  unless block
270
- return enum_for(:exec_stream, command, cwd: cwd, env: env, stdin: stdin, timeout: timeout,
271
+ return enum_for(:exec_stream, command, cwd: cwd, user: user, env: env, stdin: stdin, timeout: timeout,
271
272
  idempotency_key: idempotency_key)
272
273
  end
273
274
 
274
275
  longest = ApiDefaults::STREAMED_EXEC_TIMEOUT_SECONDS
275
- body = command_body(command, cwd, env, stdin, timeout || longest).merge("stream" => true)
276
+ body = command_body(command, cwd, env, stdin, timeout || longest, user).merge("stream" => true)
276
277
  handed_over = nil
277
278
  process_id = nil
278
279
  cursor = 0
@@ -361,8 +362,8 @@ module WithRuntime
361
362
  # once. It outlives your connection; +process(id)+ gets it back.
362
363
  # +pipe_stdin: true+ keeps input open for +write+; +pty: { cols:, rows: }+
363
364
  # gives it a terminal.
364
- def spawn(command, cwd: nil, env: nil, timeout: nil, stdin: nil, pipe_stdin: false, pty: nil, idempotency_key: nil)
365
- body = command_body(command, cwd, env, pipe_stdin ? nil : stdin, timeout)
365
+ def spawn(command, cwd: nil, user: nil, env: nil, timeout: nil, stdin: nil, pipe_stdin: false, pty: nil, idempotency_key: nil)
366
+ body = command_body(command, cwd, env, pipe_stdin ? nil : stdin, timeout, user)
366
367
  body["stdinMode"] = "pipe" if pipe_stdin
367
368
  body["pty"] = Fields.body(pty) if pty
368
369
  SandboxProcess.new(self, @t.json("POST", path("/processes"), body: body, key: idempotency_key))
@@ -385,9 +386,10 @@ module WithRuntime
385
386
 
386
387
  def room_for(wait_for_capacity) = wait_for_capacity.nil? ? @t.wait_for_capacity : [0, wait_for_capacity].max
387
388
 
388
- def command_body(command, cwd, env, stdin, timeout)
389
+ def command_body(command, cwd, env, stdin, timeout, user)
389
390
  body = command.is_a?(Array) ? { "argv" => command.map(&:to_s) } : { "command" => command.to_s }
390
391
  body["cwd"] = cwd if cwd
392
+ body["user"] = user.to_s if user
391
393
  body["env"] = env.to_h { |key, value| [key.to_s, value.to_s] } if env
392
394
  body["stdinBase64"] = [stdin.to_s.b].pack("m0") unless stdin.nil?
393
395
  body["timeoutMs"] = (timeout * 1000).round if timeout
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module WithRuntime
4
- VERSION = "0.3.0"
4
+ VERSION = "0.4.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: withruntime
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Runtime
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-10-17 00:00:00.000000000 Z
11
+ date: 2026-10-18 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: 'Linux sandboxes for agents, and every other Runtime Cloud product: streaming
14
14
  commands and terminals, files and watches, images, durable volumes and backups,