Skip to content

feat(sdk): restore transform callback with placeholder context#1335

Open
mishushakov wants to merge 1 commit into
mishushakov/network-allowout-transformfrom
mishushakov/network-transform-callback
Open

feat(sdk): restore transform callback with placeholder context#1335
mishushakov wants to merge 1 commit into
mishushakov/network-allowout-transformfrom
mishushakov/network-transform-callback

Conversation

@mishushakov
Copy link
Copy Markdown
Member

@mishushakov mishushakov commented May 19, 2026

Summary

  • Reintroduces the transform callback variant for SandboxNetworkRule (JS + Python): in addition to a static { headers: ... } object, transform can be a function receiving a typed SandboxNetworkTransformContext whose fields (sandboxId, teamId, executionId, identity.jwt / sandbox_id, team_id, execution_id, identity.jwt) are literal placeholder strings (${e2b.sandboxId}, etc.). The callback is invoked at sandbox-creation time; the resolved object — with placeholders intact — goes on the wire, and the egress proxy substitutes them per request.
  • Exports SandboxNetworkTransformContext from both SDKs.
  • Stacked on top of feat(sdk): support structured network rules with per-host transforms #1286, which ships only the static transform shape. Implemented as a straight revert of the stripping commit so the diff is small and the two PRs land cleanly in order.
  • Placeholder-resolution contract tests (transform callback resolves sandboxId placeholder in JS, test_transform_callback_resolves_sandbox_id in Python sync + async) are restored but left commented out / disabled until the proxy-side placeholder resolution ships.

Example — inject the sandbox's identity JWT (resolved per request)

await Sandbox.create({
  network: {
    allowOut: ({ rules }) => [...rules.keys()],
    rules: {
      'api.internal.example.com': [
        {
          transform: ({ identity, sandboxId }) => ({
            headers: {
              Authorization: `Bearer ${identity.jwt}`,
              'X-Sandbox-Id': sandboxId,
            },
          }),
        },
      ],
    },
  },
})
Sandbox(
    network={
        "allow_out": lambda ctx: list(ctx.rules.keys()),
        "rules": {
            "api.internal.example.com": [
                {
                    "transform": lambda ctx: {
                        "headers": {
                            "Authorization": f"Bearer {ctx.identity.jwt}",
                            "X-Sandbox-Id": ctx.sandbox_id,
                        },
                    },
                },
            ],
        },
    },
)

Notes

  • Callbacks run client-side at create-time; the SDK never resolves the placeholders itself. The wire payload contains the literal ${e2b.*} strings.
  • Depends on egress-proxy support for ${e2b.sandboxId}, ${e2b.teamId}, ${e2b.executionId}, ${e2b.identity.jwt} substitution before the disabled tests can be re-enabled.

Test plan

  • CI green (typecheck/lint/format on both SDKs)
  • Once proxy placeholder substitution ships, re-enable transform callback resolves sandboxId placeholder (JS) and test_transform_callback_resolves_sandbox_id (Python sync + async) and verify end-to-end against httpbin.e2b.team

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 19, 2026

⚠️ No Changeset found

Latest commit: 156c0a9

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@cursor
Copy link
Copy Markdown

cursor Bot commented May 19, 2026

PR Summary

Medium Risk
Adds a new callback path in network rule serialization in both JS and Python; incorrect transforms or unexpected placeholder usage could affect egress request behavior. Proxy-side placeholder substitution is not enforced/tested here, increasing integration risk.

Overview
Reintroduces SandboxNetworkRule.transform as a callable in the JS and Python SDKs, but the callback only receives frozen literal placeholder strings and the result is sent to the API without validation. The end-to-end placeholder-resolution tests are present but commented out, so the new callback behavior is not exercised in CI.

Reviewed by Cursor Bugbot for commit 156c0a9. Bugbot is set up for automated code reviews on this repo. Configure here.

@github-actions
Copy link
Copy Markdown
Contributor

Package Artifacts

Built from 20f08c4. Download artifacts from this workflow run.

JS SDK (e2b@2.19.2-mishushakov-network-transform-callback.0):

npm install ./e2b-2.19.2-mishushakov-network-transform-callback.0.tgz

CLI (@e2b/cli@2.10.1-mishushakov-network-transform-callback.0):

npm install ./e2b-cli-2.10.1-mishushakov-network-transform-callback.0.tgz

Python SDK (e2b==2.20.1+mishushakov-network-transform-callback):

pip install ./e2b-2.20.1+mishushakov.network.transform.callback-py3-none-any.whl

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant