feat(sandbox): support network_policy in the OpenSandbox provider - #2407
Draft
terrykong wants to merge 1 commit into
Draft
feat(sandbox): support network_policy in the OpenSandbox provider#2407terrykong wants to merge 1 commit into
terrykong wants to merge 1 commit into
Conversation
The provider had no way to send a networkPolicy, and provider_options rejects
unknown keys, so callers could not work around it.
That matters more than "one unsupported field" suggests. Server-side,
apply_egress_to_spec returns early when no policy is present, so the egress
sidecar is never attached at all -- meaning NO egress feature was reachable from
Gym: not filtering, not the credential proxy, not transparent MITM. Passing
{"defaultAction": "allow", "egress": []} attaches the sidecar while allowing all
traffic, which is what transparent registry interception needs.
NetworkPolicy is imported inside _to_network_policy rather than added to
_require_opensandbox_sdk's return tuple. Widening that tuple touches all eight
positional call sites and every test fake, and an earlier attempt at it produced
five conflicts on a single upstream rebase; a local import costs nothing and
keeps the change independent of that helper's shape.
Conversion uses model_validate rather than NetworkPolicy(**policy) because the
model field is default_action while the API spells it defaultAction; callers copy
the API spelling, and validating by alias accepts both.
Signed-off-by: Terry Kong <terryk@nvidia.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR 4 of 5 in the
gym sandbox debugstack (#2400 → #2401 → #2402 → #2407 → #2403).Why
The provider had no way to send a
networkPolicy, andprovider_optionsrejects unknown keys, so this was not something a caller could work around.That matters more than "one unsupported field" suggests. Server-side,
apply_egress_to_specreturns early when no policy is present, so the egress sidecar is never attached at all. In practice no egress feature was reachable from Gym — not filtering, not the credential proxy, not transparent MITM.Allow-all is the useful default: it attaches the sidecar while leaving every destination reachable.
Why it is in this stack
It sits directly below #2403 because that PR's flagship example needs it.
--provider-optionhands the value to the provider; without this the provider rejects it and the example fails withUnknown OpenSandbox provider option(s): network_policy. Shipping the CLI flags without this would mean shipping a documented command that cannot run.It is otherwise independent of the three layers below and could be reviewed on its own.
Two implementation notes
NetworkPolicyis imported inside_to_network_policy, not added to_require_opensandbox_sdk's return tuple. Widening that tuple touches all eight positional call sites plus every test fake — an earlier attempt produced five conflicts on a single upstream rebase. A local import costs nothing and keeps this independent of that helper's shape.Conversion uses
model_validate, notNetworkPolicy(**policy). The model field isdefault_actionwhile the API spells itdefaultAction; callers copy the API spelling, and validating by alias accepts both.Validated
Used to drive a sandbox whose egress sidecar transparently redirects PyPI to an in-cluster cache. A bare
pip installinside the container was served by nginx (cache=MISSfirst run,HITon repeat) with nothing in the container configured to use it. That path is unreachable without this field.Also verified through configuration alone — putting
network_policyin a server'ssandbox_spec.provider_optionsintercepts every sandbox that server creates, which is how an eval or RL run would use it, with no CLI involved.Tests
Policy reaches the SDK and round-trips by alias; omitted when unset; non-mapping raises
TypeError.