launch
launch
¶
Per-container wiring for user-owned containers.
prepare/run/cleanup compose podman flags that wire a caller-owned
container into the sandbox's services (vault token broker, vault SSH
signer, git gate, shield egress firewall) and persist enough per-container
state for cleanup to be a no-arg reverse of prepare.
Container lifecycle stays with the user; sandbox owns only the services and the per-container ancillary state (tokens, shield rules, meta JSON).
CONTAINER_BRIDGES_DIR = '/usr/local/share/terok-sandbox/bridges'
module-attribute
¶
LOOPBACK_VAULT_PORT = 9419
module-attribute
¶
SANDBOX_MANAGED_FLAGS = frozenset({'--name', '--network', '--hooks-dir', '--annotation', '--cap-add', '--cap-drop', '--userns'})
module-attribute
¶
WiringPlan(scope, shield, gate, broker, ssh)
dataclass
¶
Subsystems activated for a single prepare/run invocation.
Persisted to meta.json so cleanup reverses exactly what was
activated, without re-running the flag-defaults dance.
scope
instance-attribute
¶
shield
instance-attribute
¶
gate
instance-attribute
¶
broker
instance-attribute
¶
ssh
instance-attribute
¶
to_dict()
¶
Return a JSON-serialisable representation.
from_dict(data)
classmethod
¶
Construct from a previously-persisted to_dict payload.
Source code in src/terok_sandbox/launch.py
PerContainerResources(container_runtime_dir, token_broker_port, ssh_signer_port, gate_port)
dataclass
¶
Per-container socket dir + (for TCP mode) ports.
Allocated once per launch so the same values reach mount flags, env vars, and the sidecar JSON the supervisor reads. Keeps concurrent containers from colliding on host-global filenames or ports.
container_runtime_dir
instance-attribute
¶
Host-side directory that becomes /run/terok/ inside the
container. Contains the supervisor-bound vault.sock /
ssh-agent.sock. Created (mode 0700) before the bind mount.
token_broker_port
instance-attribute
¶
Per-container TCP port for the vault proxy in TCP mode; None
in socket mode.
ssh_signer_port
instance-attribute
¶
Per-container TCP port for the SSH signer in TCP mode; None
in socket mode.
gate_port
instance-attribute
¶
Per-container TCP port for the git gate in TCP mode; None
in socket mode.
allocate_per_container_resources(cfg, container)
¶
Compute per-container paths + (for TCP mode) ports.
Both transport modes get a per-container directory under
cfg.runtime_dir/run/<container> (mode 0700) that the caller
bind-mounts at /run/terok/ inside the container. In TCP mode,
two free ports are claimed via bind(0) + getsockname +
close so each container gets its own pair instead of fighting
over the singleton from cfg.
The narrow window between bind(0)'s close and the supervisor's
re-bind on the same port is an EADDRINUSE-loud failure mode, not
silent breakage.
Source code in src/terok_sandbox/launch.py
bridges_resource_dir()
¶
run_state_dir(cfg, container)
¶
compose(container, *, cfg, shield, gate, broker, scope, profiles=None)
¶
Compose podman args for one prepare/run invocation.
Mints any tokens needed for the active subsystems (broker/gate/ssh),
creates the per-container state directory, persists meta.json,
and returns the assembled podman flag list plus the resolved plan.
Subsystems that require scope are silently disabled (with a
stderr note) when scope is None — sandbox only enforces the
fail-closed property; nudging the caller toward a useful invocation
is the job of the CLI layer.
Raises SystemExit if shield setup is required (propagated from
ShieldManager.pre_start).
Source code in src/terok_sandbox/launch.py
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 | |
exec_podman(sandbox_args, podman_args)
¶
Replace this process with podman run.
Validates that podman_args (everything the user typed after --)
doesn't collide with sandbox-owned flags or volume targets, then
os.execvs into podman. Caller doesn't return.
Source code in src/terok_sandbox/launch.py
reject_managed_flags(podman_args)
¶
Reject user-supplied flags that sandbox owns.
Mirrors terok-shield's _reject_shield_managed_flags and adds
sandbox-specific entries (e.g. --userns).
Source code in src/terok_sandbox/launch.py
reject_managed_volumes(podman_args)
¶
Reject -v host:target whose target overlaps a sandbox mount.
Source code in src/terok_sandbox/launch.py
cleanup(container, *, cfg)
¶
Reverse a prior prepare/run for container.
Returns True when state was found and torn down, False when
there was nothing to clean up. Idempotent — safe to call repeatedly.
Source code in src/terok_sandbox/launch.py
628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 | |
format_args(args, *, output_json)
¶
Return the printable form of an args list.